I have a problem, where when I build my code it works fine, but when I run it, I get an access violation error, and ive tracked it to this little bit of code here:
void thePlayer::show_player()
{
SDL_BlitSurface(Player, NULL, ScreenSurface, &posPlayer);
SDL_SetColorKey(Player, SDL_TRUE, SDL_MapRGB(Player->format, 255, 255, 255)); //this line causes the problem
}
However I have no idea how to fix this or why it is stopping. Any help would be much appreciated!
EDIT: I have found why I have a memory violation. If I move my picture loading into the same function, it works.
HOWEVER, now I have the problem of that when I run my code, nothing happens, nothing is Blitted to the Screen.
Edited show_player code:
void thePlayer::show_player()
{
Player = SDL_LoadBMP("spaceship.bmp");
if (Player == NULL)
{
cout<<"Error in loading player."<<SDL_GetError()<<endl;
}
SDL_BlitSurface(Player, NULL, ScreenSurface, &posPlayer);
SDL_SetColorKey(Player, SDL_TRUE, SDL_MapRGB(Player->format, 255, 255, 255));
SDL_UpdateWindowSurface(Window);
}
Like I said, everything builds, but nothing is shown on screen.