Repository navigation
glue: re-bind shared GL context before destroying shared GL objects (windows) - #38
igagis-bot wants to merge 4 commits into
Conversation
…windows) On exit, the windows (and their GL contexts) are destroyed before the shared GL objects (common shaders, common render objects, shared resource textures) still owned by the glue, so those GL objects were deleted with no current GL context on the thread, triggering GL_INVALID_OPERATION in the debug GL error assertions. Add a guard member to application_glue that is destroyed right before the shared GL objects and re-binds the shared GL context (which outlives them) on this thread.
# Conflicts: # src/ruisapp/glue/windows/application.hxx
Main now removes the shared gl context window in the Vulkan variant, so guard the shared gl context restorer the same way. Vulkan has no 'current context' to re-bind. Also, declare the restorer before ruis_style_provider to satisfy -Wreorder, and format the code with clang-format.
|
It is better to do the other approach. the ruis::render::factory should have protected virtual bind(){} method (vulkan impl will not override it leaving it empty). then concrete factories can override it to bind the factory's native rendering context. the ruis::render::context shoukld be a friend of the ruis::render::factory. when ruis::render::context is destroyed it checks if the context_Stack is empty, if not it binds the top context, if it is empty, then it will call this->factory->bind(). then it shoulkd fix it for all? |
|
Implemented as suggested, in the render layer instead of the glue:
Yes, this fixes it for all glue implementations (windows, xorg, wayland, ...) at once, since the shared render objects are now destroyed with a valid current context on every platform. Verified locally on Windows: both the opengl and opengles test apps now exit cleanly on window close (previously the opengl one crashed with GL_INVALID_OPERATION during teardown). Closing this PR as obsolete — the glue-level guard is removed, the branch now matches main. |
Fixes a crash on exit (ESC / quit) of OpenGL apps:
GL_INVALID_OPERATIONinopengl_buffer::~opengl_buffer()debug assertions (exit code 127).Root cause
On exit,
application_gluemembers are destroyed in reverse declaration order: the windows (and their GL contexts) are destroyed first, leaving no current GL context on the thread. The shared GL objects — common shaders, common render objects (unit-quad VBO/index buffers), and shared resource textures in the style provider / resource loader — are destroyed after the windows, so their GL delete calls ran with no current context. The shared GL context (whose HGLRC these objects belong to) still existed but was no longer current.Fix
Add a guard member (
restore_shared_gl_context_on_destruction) toapplication_glue, declared after all owners of shared GL objects so it is destroyed before them; its destructor re-binds the shared GL context (which outlives the shared objects) on the current thread.Verification
run{quit}) before the fix:GL_INVALID_OPERATION(1282),wglGetCurrentContext() == NULL, exit code 127.