problem with Access Violation, and I'm not sure where
Matt via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 10 19:59:38 PDT 2014
I previously asked this over in the DigitalMars.D
board(http://forum.dlang.org/thread/huftyrtbomaimuqkmkmy@forum.dlang.org#post-hrqvqlzzbkgafvjdtjnb:40forum.dlang.org),
but it was suggested I ask it over here instead.
I have the following code and, despite trying to pinpoint it with
try-catch blocks, I keep getting an Access Violation, and I'm
really not sure where.
I'm using dub to build, but I've tried manually building as well,
and I just get the same problem comes up.
The only module in the program is as follows (with the wrapper
modules ripped out, so it's straight calls);
---
module app;
// own modules
import derelict.sdl2.sdl;
// standard library modules
import std.json;
import std.file;
import std.conv;
import std.stdio;
import std.datetime;
void main (string[] args){
DerelictSDL2.load();
if (!DerelictSDL2.isLoaded) assert(0, "DerelictSDL2 failed to
load!");
SDL_Init( SDL_INIT_EVERYTHING );
scope(exit) SDL_Quit();
SDL_Window* window;
JSONValue cfg;
try{
cfg = loadConfig;
auto width = to!int (cfg["window"]["width"].integer);
auto height = to!int (cfg["window"]["height"].integer);
window = SDL_CreateWindow (cfg["window"]["caption"].str.ptr,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height,
SDL_WINDOW_SHOWN);
}
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{
int* keys;
ubyte* numkeys;
while (true){
SDL_PumpEvents();
numkeys = SDL_GetKeyboardState (keys);
if (keys[SDL_SCANCODE_LALT] && keys[SDL_SCANCODE_F4]){
SDL_DestroyWindow (window);
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");
}
}
---
If anyone can help me with this, I would very much appreciate it.
More information about the Digitalmars-d-learn
mailing list