diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 399268d4a..2d1e064e4 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -626,7 +626,7 @@ void LoadBackgroundArt(const char *pszFile, int frames) if (IsHardwareCursorEnabled() && ArtCursor.surface != nullptr && GetCurrentCursorInfo().type() != CursorType::UserInterface) { #if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_SetSurfacePalette(ArtCursor.surface.get(), Palette); + SDL_SetSurfacePalette(ArtCursor.surface.get(), Palette.get()); SDL_SetColorKey(ArtCursor.surface.get(), 1, 0); #endif SetHardwareCursor(CursorInfo::UserInterfaceCursor()); diff --git a/Source/dx.cpp b/Source/dx.cpp index 05ad69d2e..13bebdbb0 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -28,7 +28,7 @@ SDLTextureUniquePtr texture; #endif /** Currently active palette */ -SDL_Palette *Palette; +SDLPaletteUniquePtr Palette; unsigned int pal_surface_palette_version = 0; /** 24-bit renderer texture surface */ @@ -84,7 +84,7 @@ void CreateBackBuffer() #ifndef USE_SDL1 // In SDL2, `pal_surface` points to the global `palette`. - if (SDL_SetSurfacePalette(pal_surface, Palette) < 0) + if (SDL_SetSurfacePalette(pal_surface, Palette.get()) < 0) ErrSdl(); #else // In SDL1, `pal_surface` owns its palette and we must update it every @@ -206,7 +206,7 @@ void dx_cleanup() return; SDL_FreeSurface(pal_surface); pal_surface = nullptr; - SDL_FreePalette(Palette); + Palette = nullptr; SDL_FreeSurface(renderer_texture_surface); #ifndef USE_SDL1 texture = nullptr; @@ -240,10 +240,7 @@ void dx_reinit() void InitPalette() { - Palette = SDL_AllocPalette(256); - if (Palette == nullptr) { - ErrSdl(); - } + Palette = SDLWrap::AllocPalette(256); } void BltFast(SDL_Rect *srcRect, SDL_Rect *dstRect) diff --git a/Source/hwcursor.cpp b/Source/hwcursor.cpp index d27df25a7..3b43df191 100644 --- a/Source/hwcursor.cpp +++ b/Source/hwcursor.cpp @@ -112,7 +112,7 @@ bool SetHardwareCursorFromSprite(int pcurs) return false; OwnedSurface out { size }; - SDL_SetSurfacePalette(out.surface, Palette); + SDL_SetSurfacePalette(out.surface, Palette.get()); // Transparent color must not be used in the sprite itself. // Colors 1-127 are outside of the UI palette so are safe to use. diff --git a/Source/palette.cpp b/Source/palette.cpp index 6ca8330f8..7b5a16892 100644 --- a/Source/palette.cpp +++ b/Source/palette.cpp @@ -163,7 +163,7 @@ void CycleColorsReverse(int from, int to) void palette_update(int first, int ncolor) { assert(Palette); - if (SDLC_SetSurfaceAndPaletteColors(pal_surface, Palette, system_palette, first, ncolor) < 0) { + if (SDLC_SetSurfaceAndPaletteColors(pal_surface, Palette.get(), system_palette, first, ncolor) < 0) { ErrSdl(); } pal_surface_palette_version++; diff --git a/Source/utils/display.h b/Source/utils/display.h index b1c2aa348..58ee24ff2 100644 --- a/Source/utils/display.h +++ b/Source/utils/display.h @@ -22,7 +22,7 @@ extern SDL_Renderer *renderer; extern SDLTextureUniquePtr texture; #endif -extern SDL_Palette *Palette; +extern SDLPaletteUniquePtr Palette; extern SDL_Surface *pal_surface; extern unsigned int pal_surface_palette_version;