From 07bf4e9c100b5e94c59b8eb06246ea445921f6c3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sat, 14 Feb 2026 09:29:47 +0100 Subject: [PATCH] [client,sdl] improve cursor updates * use std::unique_ptr for temporary SDL_Surface (ease up cleanup) * better logging of errors (add full surface details) --- client/SDL/SDL3/sdl_pointer.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/client/SDL/SDL3/sdl_pointer.cpp b/client/SDL/SDL3/sdl_pointer.cpp index 322269190..07d95a510 100644 --- a/client/SDL/SDL3/sdl_pointer.cpp +++ b/client/SDL/SDL3/sdl_pointer.cpp @@ -170,31 +170,33 @@ bool sdl_Pointer_Set_Process(SdlContext* sdl) const auto hidpi_scale = sdl->pixelToScreen(fw->id(), SDL_FPoint{ static_cast(ptr->image->w), static_cast(ptr->image->h) }); - auto normal = SDL_CreateSurface(static_cast(hidpi_scale.x), - static_cast(hidpi_scale.y), ptr->image->format); + std::unique_ptr normal{ + SDL_CreateSurface(static_cast(hidpi_scale.x), static_cast(hidpi_scale.y), + ptr->image->format), + SDL_DestroySurface + }; assert(normal); - if (!SDL_BlitSurfaceScaled(ptr->image, nullptr, normal, nullptr, + if (!SDL_BlitSurfaceScaled(ptr->image, nullptr, normal.get(), nullptr, SDL_ScaleMode::SDL_SCALEMODE_LINEAR)) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_BlitSurfaceScaled failed"); return false; } - if (!SDL_AddSurfaceAlternateImage(normal, ptr->image)) + if (!SDL_AddSurfaceAlternateImage(normal.get(), ptr->image)) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_AddSurfaceAlternateImage failed"); return false; } - ptr->cursor = SDL_CreateColorCursor(normal, static_cast(pos.x), static_cast(pos.y)); + ptr->cursor = + SDL_CreateColorCursor(normal.get(), static_cast(pos.x), static_cast(pos.y)); if (!ptr->cursor) { - WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_CreateColorCursor(%fx%f) failed", - static_cast(pos.x), static_cast(pos.y)); + WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_CreateColorCursor(display:%s, pixel:%s} failed", + sdl::utils::toString(pos).c_str(), sdl::utils::toString(orig).c_str()); return false; } - SDL_DestroySurface(normal); - if (!SDL_SetCursor(ptr->cursor)) { WLog_Print(sdl->getWLog(), WLOG_ERROR, "SDL_SetCursor failed");