diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index f4e80292bf0..494e46d9b7b 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -6986,10 +6986,6 @@ static void gwl_registry_wl_seat_remove(GWL_Display *display, void *user_data, c zwp_tablet_seat_v2_destroy(seat->wp.tablet_seat); } - if (seat->cursor.custom_data) { - munmap(seat->cursor.custom_data, seat->cursor.custom_data_size); - } - /* Disable all capabilities as a way to free: * - `seat.wl_pointer` (and related cursor variables). * - `seat.wl_touch`. @@ -6999,6 +6995,20 @@ static void gwl_registry_wl_seat_remove(GWL_Display *display, void *user_data, c gwl_seat_capability_keyboard_disable(seat); gwl_seat_capability_touch_disable(seat); + /* Run after tablet & input devices have been disabled + * to ensure the buffer from a *visible* cursor never destroyed. + * + * Note that most compositors will have already releases the buffer, + * in that case this will have been set to null. + * However this isn't guaranteed, see: #145557. */ + if (seat->cursor.wl.buffer) { + wl_buffer_destroy(seat->cursor.wl.buffer); + } + + if (seat->cursor.custom_data) { + munmap(seat->cursor.custom_data, seat->cursor.custom_data_size); + } + /* Un-referencing checks for nullptr case. */ xkb_state_unref(seat->xkb.state); xkb_state_unref(seat->xkb.state_empty);