I have a small script which is meant to get the user’s screen resolution and assign it to a variable but i get an Access Violation error and not sure how to fix it (I’m quite new to this language) so was hoping some one can show me how I should write it.
This is my setup:
//get player's screen info
const SDL_VideoInfo* myScreen = SDL_GetVideoInfo();
//SDL screen
SDL_Surface *screen;
int reso_x = myScreen->current_w; //resolution width (ERROR here)
int reso_y = myScreen->current_h; //resolution height
Uint8 video_bpp = 32;
Uint32 videoflags = SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;// | SDL_FULLSCREEN;
/* Initialize the SDL library */
if ( SDL_Init(videoflags) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(1);
}
//setup Screen
screen = SDL_SetVideoMode(reso_x, reso_y, video_bpp, videoflags|SDL_FULLSCREEN);
Does any one know the cause of my mistake?
You shouldn’t make any SDL calls before SDL_init. My guess is GetVideoInfo is returning null because you are not in a valid state at that point. Also the flags you are passing to init are wrong, it should be SDL_INIT_VIDEO not what kind of video you want. Your video flags should go to the SetVideoMode function.