From 9755d0d879ef20f168039cb4f5554e97ac8e7b4a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Apr 2024 18:06:03 +0530 Subject: [PATCH] Wayland: Ensure context is correct when calling wl_egl_window_resize Fixes #7373 (I hope) --- glfw/wl_window.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index e5cd1e226..9dae97ae6 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -356,6 +356,14 @@ _glfwWaylandWindowScale(_GLFWwindow *window) { return ans; } +#define run_with_context(window, expression) { \ + const _GLFWwindow *current_context = (_GLFWwindow*)glfwGetCurrentContext(); \ + const bool needs_swap = window != current_context; \ + if (needs_swap) glfwMakeContextCurrent((GLFWwindow*)window); \ + expression; \ + if (needs_swap) glfwMakeContextCurrent((GLFWwindow*)current_context); \ +} + static void resizeFramebuffer(_GLFWwindow* window) { double scale = _glfwWaylandWindowScale(window); @@ -363,7 +371,7 @@ resizeFramebuffer(_GLFWwindow* window) { int scaled_height = (int)round(window->wl.height * scale); debug("Resizing framebuffer of window: %llu to: %dx%d window size: %dx%d at scale: %.3f\n", window->id, scaled_width, scaled_height, window->wl.width, window->wl.height, scale); - wl_egl_window_resize(window->wl.native, scaled_width, scaled_height, 0, 0); + run_with_context(window, wl_egl_window_resize(window->wl.native, scaled_width, scaled_height, 0, 0)); update_regions(window); window->wl.waiting_for_swap_to_commit = true; _glfwInputFramebufferSize(window, scaled_width, scaled_height);