Getting an access violation before main starts
Matt via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 10 17:00:45 PDT 2014
I was wondering if anyone could help with a problem I'm having.
My program compiles properly, and has all up-to-date files and
DLLs (SDL2, SDL2-image, SDL2-ttf, all the other DLLs that are
required by these). However, when I run it, I get "object.Error:
Access Violation", which, of course, means something isn't
getting created.
I'm using dub to build (although I get the same problem when
trying to build manually).
My main program looks like this:
---
void main (string[] args){
Window window;
JSONValue cfg;
Input input;
try{
window = new Window ();
cfg = loadConfig;
window.create (cfg["window"]["caption"].str, to!int
(cfg["window"]["width"].integer), -1, -1, to!int
(cfg["window"]["height"].integer),
(cfg["window"]["windowed"].type == JSON_TYPE.FALSE) ? true :
false );
window.releaseMouse;
input = window.getInput ();
}
catch(Error e){
writeln ("error occurred before timing variable setup");
return;
}
// set up timing variables
auto duration = TickDuration (cfg["graphics"]["ticks"].integer);
auto current_tick = Clock.currAppTick;
auto target_tick = current_tick + duration;
auto target_margin = target_tick + (duration/2);
// main loop
try{
while (!window.is_dead){
auto keys = input.getKeyboardState ();
/// TODO: there is a range error occurring in keys.keys when
holding down left alt. Check for other modifier keys
if (/*(keys.mods &
KeyMods.LeftAlt)*/keys.scans[ScanCode.LeftAlt] &&
keys.scans[ScanCode.F4]){
window.destroy;
break;
}
current_tick = Clock.currAppTick;
if (current_tick >= target_tick){
// this way, it will wait for the next frame, if there is
less than half the time to the next frame left
if (current_tick < target_margin){
// update graphics and physics
}
// prep for next tick
target_tick += duration;
target_margin += duration;
}
}
}
catch(Error e){
writeln ("error occurred during main loop");
}
}
---
Both Window and Input are my own classes, which I've checked for
leaks, and don't appear to have any. They are basically wrappers
around SDL functionality. I can include the source if people
want, but it's pretty long.
The try-catch blocks were put in to see if I could track down
which part of the code the error's occurring in, which is why I
believe it to be happening before main() is called.
I'd appreciate any help that you guys can give, and many thanks
in advance.
More information about the Digitalmars-d
mailing list