Basically, my code is just meant to load a BMP file, just to test SDL in Visual Studio. It works in Code::Blocks with MingW, and it worked in VS up until I added
VS is pointing towards the key's declaration line, and saying "Unhandled exception at 0x00d9158a in SDL_Tutorial.exe: 0xC0000005: Access violation reading location 0x00000004." My entire program:Code:Uint32 colorkey = SDL_MapRGB(img->format, 0xFF, 0, 0xFF); //declare the key SDL_SetColorKey(img, SDL_SRCCOLORKEY, colorkey); // set the key
Code:#include <SDL.h> int main( int argc, char* args[] ) { //Start SDL SDL_Init( SDL_INIT_EVERYTHING ); //vars SDL_Surface *img; SDL_Surface *buffer; SDL_Rect crop; SDL_Rect loc; crop.x = 0; crop.y = 0; crop.w = 32; crop.h = 32; loc.x = 280; loc.y = 280; //load image onto screen img = SDL_LoadBMP("snakey.bmp"); Uint32 colorkey = SDL_MapRGB(img->format, 0xFF, 0, 0xFF); SDL_SetColorKey(img, SDL_SRCCOLORKEY, colorkey); //make magneta invisible buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE ); SDL_BlitSurface(img, &crop, buffer, &loc); SDL_Flip(buffer); SDL_Delay(2000); //Quit SDL SDL_FreeSurface(buffer); SDL_FreeSurface(img); SDL_Quit(); return 0; }



LinkBack URL
About LinkBacks


