gtk-demo/example_glarea.cc throws "Couldn't find current GLX or EGL context.\n" on closing window
Compiling the gtkmm-demos from source, then selecting "OpenGL Area" -> "Run" and then closing the window results in:
┌─gerlof@gerlof-laptop ~/packages/arch/packages/gtkmm3/trunk/src/gtkmm/demos (makepkg *) $
└─╼./gtk-demo/gtkmm-demo
lt-gtkmm-demo: ../libepoxy/src/dispatch_common.c:863: epoxy_get_proc_address: Assertion `0 && "Couldn't find current GLX or EGL context.\n"' failed.
Aborted (core dumped)
Software versions:
- gtk: 3.24.13
- gtkmm-3.0: 3.24.2
- libepoxy: 1.5.4
See also https://mail.gnome.org/archives/gtkmm-list/2019-December/msg00000.html
To summarize from the mailing list:
A minimal application illustrating the issue (almost verbatim copy of the gtkmm-demo):
https://gist.github.com/gfokkema/a0c73de5c9df476b5b31057ebb63394f/39cac57cca915432c43ecb4d5dcb8eaad35fabf0
Results in the output:
┌─gerlof@gerlof-laptop ~/workspace/gtk-renderer (master *+) $
└─╼./a.out
Realize context: 0x55d1f7aafe60
Destructor context: 0x55d1f7aafe60
Unrealize context: (nil)
a.out: ../libepoxy/src/dispatch_common.c:863: epoxy_get_proc_address: Assertion `0 && "Couldn't find current GLX or EGL context.\n"' failed.
Aborted (core dumped)
Setting breakpoints at:
- gtkglarea.c:195: gtk_gl_area_dispose
- gtkglarea.c:575: gtk_gl_area_unrealize
Reveals that when using Gtk::GLArea as a class member, gtk_gl_area_dispose is called before gtk_gl_area_unrealize.
Since gtk_gl_area_dispose clears the opengl context, gtk_gl_area_unrealize then has no reference to the context anymore, resulting in (nil).
When using Gtk::GLArea as a managed widget, the issue disappears, gtk_gl_area_unrealize is called before gtk_gl_area_dispose.
The last revision of the linked gist shows changes i made for a working version:
https://gist.github.com/gfokkema/a0c73de5c9df476b5b31057ebb63394f/revisions
https://gist.github.com/gfokkema/a0c73de5c9df476b5b31057ebb63394f/5bef8962fa2de35d30fc9e84dcf7536d35ab8c8c
Results in the output:
┌─gerlof@gerlof-laptop ~/workspace/gtk-renderer (master *+) $
└─╼./a.out
Realize context: 0x5613daaa35d0
Destructor context: 0x5613daaa35d0
Unrealize context: 0x5613daaa35d0