mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-12-31 10:42:12 +00:00
Fixes #6872 This commit explicitly acquires the GL context in the `unrealize` signal handler of the GTK Surface prior to cleaning up GPU resources. A GLArea only guarantees that the associated GdkContext is current for the `render` signal (see the docs[1]). This is why our OpenGL renderer "defers" various operations such as resize, font grid changing, etc. (see the `deferred_`-prefix fields in `renderer/OpenGL.zig`). However, we missed a spot. The `gtk-widget::unrealize` signal is emitted when the widget is destroyed, and it is the last chance we have to clean up our GPU resources. But it is not guaranteed that the GL context is current at that point, and we weren't making it current. On the NGL GTK renderer, this was freeing GPU resources we didn't own. As best I can understand, the old GL renderer only ever used a handful of GL resources that were early in the ID space, so by coincidence we were probably freeing nothing and everything was fine. But with the new NGL renderer uses a LOT more GL resources (make a few splits and the ID space is already in the thousands, from GTK!), so we were freeing real resources that we didn't own, which caused rendering issues. :) I suspect the above also resulted in VRAM memory leaks (which would be RAM memory leaks for unified memory GPUs). This potentially relates to #5491. The fix is to explicitly make the GL context current in the `unrealize` handler. [1]: https://docs.gtk.org/gtk4/method.GLArea.make_current.html