Search code examples
c++openglsdlfreesdl-2

Am i deleting sdl2 and opengl right c++


I was wondering if i am deleting sdl and opengl the right way.

Here is the code of my deconstructor:

Mix_CloseAudio();

// Close and destroy the window
SDL_DestroyWindow(window);
SDL_GL_DeleteContext(gContext);

// Clean up
SDL_Quit();

glDeleteProgram(programID);
glDeleteTextures(1, &textureID);

Solution

  • Nope, that's almost exactly backwards.

    The SDL window owns the GL context, and the GL context owns the GL objects.

    You want something like this:

    Mix_CloseAudio();
    
    glDeleteProgram(programID);
    glDeleteTextures(1, &textureID);
    
    SDL_GL_DeleteContext(gContext);
    
    // Close and destroy the window
    SDL_DestroyWindow(window);
    
    // Clean up
    SDL_Quit();