SDL: wayland: Only destroy tool frame callbacks if the cursor is the one being destroyed (7627f)

From 7627f5d838fe0871805c1e8c456927f5bd5ebeb8 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Fri, 16 Jan 2026 12:31:10 -0500
Subject: [PATCH] wayland: Only destroy tool frame callbacks if the cursor is
 the one being destroyed

(cherry picked from commit 202fdb27954c963c38432966fef8069c6d781645)
---
 src/video/wayland/SDL_waylandmouse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index db8381ca1b6d1..c70ea1b5eac53 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -910,9 +910,9 @@ static void Wayland_FreeCursorData(SDL_CursorData *d)
 
         SDL_WaylandPenTool *tool;
         wl_list_for_each (tool, &seat->tablet.tool_list, link) {
-            Wayland_CursorStateDestroyFrameCallback(&tool->cursor_state);
-
             if (tool->cursor_state.current_cursor == d) {
+                Wayland_CursorStateDestroyFrameCallback(&tool->cursor_state);
+
                 // Custom cursor buffers are about to be destroyed, so ensure they are detached.
                 if (!d->is_system_cursor && tool->cursor_state.surface) {
                     wl_surface_attach(seat->pointer.cursor_state.surface, NULL, 0, 0);