So I got into SDL2 with C++ quite recently and I did this very simple code :
int main(int argc, char** argv)
{
SDL_Event *event;
bool done = false;
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::cerr << "Problèmes pour initialiser la SDL : " << SDL_GetError() << std::endl;
return 1;
}
SDL_Window *window = 0;
window = SDL_CreateWindow("Mopion", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
if(window == 0)
{
done = true;
}
while(!done)
{
while(SDL_PollEvent(event))
{
switch(event->type)
{
case SDL_QUIT:
done = true;
break;
case SDL_KEYUP:
if(event->key.keysym.sym == SDLK_q)
{
done = true;
}
break;
default:
break;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
While that code executes at first quite well, when I hit the "Q" key, the window closes but I got a Windows Error Window saying that "My program stopped working." which is not very convenient.
Using the debugger, I found that everything is fine until SDL_Quit() is called.
Anyone has any idea why this is going on ?
Thanks a lot !