From 5b4232b094c461c07a88d8f1c0e2582e48067ded Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 15 Dec 2023 14:15:32 -0800 Subject: [PATCH] renderer/opengl: acquire lock to prep kitty images Fixes #1101 GTK forces all GLArea drawing to happen on the GUI thread. In this scenario, `updateFrame` and `drawFrame` could be happening in parallel. This commit grabs the lock while updating the Kitty image protocol state since that is used by both functions. We already have a mutex called "draw_mutex" that we hold while we're modifying data that could be shared by this separate draw thread. We should reuse that here. --- src/renderer/OpenGL.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index bbb36b730..61d3bd7fe 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -709,6 +709,11 @@ pub fn updateFrame( // We only do this if the Kitty image state is dirty meaning only if // it changes. if (state.terminal.screen.kitty_images.dirty) { + // prepKittyGraphics touches self.images which is also used + // in drawFrame so if we're drawing on a separate thread we need + // to lock this. + if (single_threaded_draw) self.draw_mutex.lock(); + defer if (single_threaded_draw) self.draw_mutex.unlock(); try self.prepKittyGraphics(state.terminal); }