Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GL Context is double-freed #15

Open
rndtrash opened this issue May 10, 2021 · 0 comments
Open

GL Context is double-freed #15

rndtrash opened this issue May 10, 2021 · 0 comments

Comments

@rndtrash
Copy link
Contributor

rndtrash commented May 10, 2021

Problem: donut always exits ungracefully.

+---------------------------------------------------+
|    _____        /--------------------------\      |
|   /     \      |                            |     |
| \/\/     |    /     donut game               \    |
|  |  (o)(o)    |                              |    |
|  C   .---_)   \_   _________________________/     |
|   | |.___|      | /                               |
|   |  \__/      <_/                                |
|   /_____\                                         |
|  /_____/ \                                        |
| /         \                                       |
+---------------------------------------------------+

hellooooooooooo new york!!!!
Initializing SDL...
SDL Version/Compiled 2.0.12
SDL Version/Linked 2.0.12
OpenGL version loaded: 4.6
Vendor: NVIDIA Corporation
Renderer: GeForce GTX 1050 Ti/PCIe/SSE2
Version: 4.6.0 NVIDIA 460.73.01
// some unrelated messages //
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  151 (GLX)
  Minor opcode of failed request:  4 (X_GLXDestroyContext)
  Serial number of failed request:  3409
  Current serial number in output stream:  3409
AL lib: (EE) alc_cleanup: 1 device not closed

Theory: this error is caused by double-free of GL context.
Proof of concept:

#include <GL/glew.h>
#include <SDL2/SDL.h>

int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_VIDEO); /* Initialises Video Subsystem in SDL */

    /* Setting up OpenGL version and profile details for context creation */
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
    
    /* A 800x600 window. Pretty! */
    SDL_Window* window = SDL_CreateWindow
        (
        "SDL Context",
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
        800, 600,
        SDL_WINDOW_OPENGL
        );
    
    /* Creating OpenGL Context */
    SDL_GLContext gl_context = SDL_GL_CreateContext(window);

    /* Loading Extensions */
    glewExperimental = GL_TRUE;
    glewInit();

    /* The following code is for error checking. 
    *  If OpenGL has initialised properly, this should print 1.
    *  Remove it in production code.
    */
    GLuint vertex_buffer;
    glGenBuffers(1, &vertex_buffer);
    printf("%u\n", vertex_buffer);
    /* Error checking ends here */

    /* Main Loop */
    SDL_Event window_event;
    while(1) {
        if (SDL_PollEvent(&window_event)) {
            if (window_event.type == SDL_QUIT) {
                /* If user is exiting the application */
                break;
            }
        }
        /* Swap the front and back buffer for flicker-free rendering */
        SDL_GL_SwapWindow(window);
    }
    
    /* Freeing Memory */
    glDeleteBuffers(1, &vertex_buffer);
    SDL_GL_DeleteContext(gl_context);
    SDL_GL_DeleteContext(gl_context); // <=
    SDL_Quit();

    return 0;
}
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  151 (GLX)
  Minor opcode of failed request:  4 (X_GLXDestroyContext)
  Serial number of failed request:  299
  Current serial number in output stream:  299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant