Hello,
I’m currently making a game and an engine using SDL2 and OpenGL and it used to be a simple executable. Now I moved the engine part out into a library so multiple applications can use it. That way I can easily make separate tools using functions provided by the engine. I also moved the actual game part into a separate program. Everything delightfully works just fine. Except one thing: Upon program exit, SDL_Quit() freezes and the program will not continue. Before migrating it to a DLL, it worked just fine. This is my cleanup code:
SDL_FreeCursor(m_pCursor);
SDL_GL_DeleteContext(m_context);
SDL_DestroyWindow(window());
SDL_Quit(); // <-- hangs
The code that does the initializing is below:
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "SDL initialized." << std::endl;
}
else
{
return false;
}
int flags{ 0 };
flags = Config::fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_SHOWN;
flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
m_pWindow = SDL_CreateWindow("Game", Config::posX == -1 ? SDL_WINDOWPOS_CENTERED : Config::posX, Config::posY == -1 ? SDL_WINDOWPOS_CENTERED : Config::posY, Config::width, Config::height, flags);
if (m_pWindow == nullptr)
return false;
m_context = SDL_GL_CreateContext(m_pWindow);
if (m_context == nullptr)
return false;
glewExperimental = GL_TRUE;
auto init_res = glewInit();
if(init_res != GLEW_OK)
{
std::cout << glewGetErrorString(glewInit()) << std::endl;
}
if( SDL_GL_SetSwapInterval( 1 ) < 0 ) // <-- vsync disabled
{
printf( "Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError() );
}
m_pCursor = init_system_cursor(arrow);
SDL_SetCursor(m_pCursor);
If I try to call SDL_Quit() right after initializing SDL, it works fine, but when I do it at shut down it doesn’t seem to like it.
Can anyone think of a reason why this might be happening?
Thanks
Matthias