Skip to content

Commit

Permalink
Fix opengl context leak on vid_restart (causing thread, memory and ot…
Browse files Browse the repository at this point in the history
…her resource leaks)

SDL opengl context must be destroyed before destroying its window and
also before SDL_QuitSubSystem(SDL_INIT_VIDEO) to prevent leaks
  • Loading branch information
aufau committed May 1, 2024
1 parent 5ee5c00 commit cd96799
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/sdl/sdl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ static rserr_t GLimp_SetMode(glconfig_t *glConfig, const windowDesc_t *windowDes
0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
);

// Destroy existing state if it exists
if( opengl_context != NULL )
{
SDL_GL_DeleteContext( opengl_context );
opengl_context = NULL;
}

// If a window exists, note its display index
if ( screen != NULL )
{
Expand Down Expand Up @@ -652,13 +659,6 @@ static rserr_t GLimp_SetMode(glconfig_t *glConfig, const windowDesc_t *windowDes
}
Com_Printf( " %d %d\n", winWidth, winHeight);

// Destroy existing state if it exists
if( opengl_context != NULL )
{
SDL_GL_DeleteContext( opengl_context );
opengl_context = NULL;
}

if ( r_centerWindow->integer )
{
x = SDL_WINDOWPOS_CENTERED_DISPLAY( display );
Expand Down Expand Up @@ -1090,8 +1090,17 @@ void WIN_Shutdown( void )

IN_Shutdown();

if ( opengl_context ) {
SDL_GL_DeleteContext( opengl_context );
opengl_context = NULL;
}

if ( screen ) {
SDL_DestroyWindow( screen );
screen = NULL;
}

SDL_QuitSubSystem( SDL_INIT_VIDEO );
screen = NULL;
}

void GLimp_EnableLogging( qboolean enable )
Expand Down

0 comments on commit cd96799

Please sign in to comment.