int main( int argc, char* args[] )
{
if( SDL_Init(SDL_INIT_EVERYTHING) < 0 )
std::cout<<"unable to init sdl";
SDL_Surface *screen = SDL_SetVideoMode(800,600,32,SDL_DOUBLEBUF);
std::cout<<"before while\n";
SDL_Event event;
while(SDL_PollEvent(&event))
{
std::cout<<"in while\n";
if(event.type == SDL_QUIT)
std::cout<<"SDL_QUIT\n";
}
std::cout<<"after while\n";
SDL_Quit();
}
For some unknown reason this SDL app quits after running in the while loop 4 times without me killing/closing/etc it and without printing “SDL_QUIT” to stdout.
Is there a reason for this? How do I fix it?
You need to keep your application alive by creating a main loop for it. As of now, your application just quits after you poll all the initial events: