diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index aebdf7ac8c7..86333eb73a7 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -1596,6 +1596,13 @@ static int gwl_display_seat_index(GWL_Display *display, const GWL_Seat *seat) return index; } +/** + * Callers must null check the return value unless it's known there is a seat. + * + * \note Running Blender in an instance of the Weston compositor + * called with `--backend=headless` causes there to be no seats. + * CMake's `WITH_UI_TESTS` does this. + */ static GWL_Seat *gwl_display_seat_active_get(const GWL_Display *display) { if (UNLIKELY(display->seats.empty())) { @@ -8476,6 +8483,10 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_check(const GHOST_TStandardCurs { /* No need to lock `server_mutex`. */ GWL_Seat *seat = gwl_display_seat_active_get(display_); + if (UNLIKELY(!seat)) { + return GHOST_kFailure; + } + const wl_cursor *wl_cursor = gwl_seat_cursor_find_from_shape(seat, cursorShape, nullptr); if (wl_cursor == nullptr) { return GHOST_kFailure; @@ -8602,7 +8613,9 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_visibility_set(const bool visible) GHOST_TCapabilityFlag GHOST_SystemWayland::getCapabilities() const { - GHOST_ASSERT(has_wl_trackpad_physical_direction != -1, + /* It's possible there are no seats, ignore the value in this case. */ + GHOST_ASSERT(((gwl_display_seat_active_get(display_) == nullptr) || + (has_wl_trackpad_physical_direction != -1)), "The trackpad direction was expected to be initialized"); return GHOST_TCapabilityFlag( @@ -8628,7 +8641,9 @@ GHOST_TCapabilityFlag GHOST_SystemWayland::getCapabilities() const /* This WAYLAND back-end has not yet implemented desktop color sample. */ GHOST_kCapabilityDesktopSample | /* This flag will eventually be removed. */ - (has_wl_trackpad_physical_direction ? 0 : GHOST_kCapabilityTrackpadPhysicalDirection))); + ((has_wl_trackpad_physical_direction == 1) ? + 0 : + GHOST_kCapabilityTrackpadPhysicalDirection))); } bool GHOST_SystemWayland::cursor_grab_use_software_display_get(const GHOST_TGrabCursorMode mode) @@ -9090,11 +9105,12 @@ void GHOST_SystemWayland::seat_active_set(const GWL_Seat *seat) wl_seat *GHOST_SystemWayland::wl_seat_active_get_with_input_serial(uint32_t &serial) { GWL_Seat *seat = gwl_display_seat_active_get(display_); - if (seat) { - serial = seat->data_source_serial; - return seat->wl.seat; + if (UNLIKELY(!seat)) { + return nullptr; } - return nullptr; + + serial = seat->data_source_serial; + return seat->wl.seat; } bool GHOST_SystemWayland::window_surface_unref(const wl_surface *wl_surface)