Browse Source

Don't free PalSurface when it was obtained from SDL_GetVideoSurface

pull/2867/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
d4d89077cd
  1. 2
      Source/DiabloUI/art_draw.cpp
  2. 4
      Source/DiabloUI/diabloui.cpp
  3. 2
      Source/DiabloUI/diabloui.h
  4. 33
      Source/dx.cpp
  5. 2
      Source/dx.h
  6. 2
      Source/palette.cpp
  7. 6
      Source/scrollrt.cpp
  8. 2
      Source/utils/display.h

2
Source/DiabloUI/art_draw.cpp

@ -16,7 +16,7 @@ void UpdatePalette(Art *art, const SDL_Surface *output)
return;
if (output == nullptr || output->format->BitsPerPixel != 8)
output = pal_surface;
output = PalSurface;
if (SDLC_SetSurfaceColors(art->surface.get(), output->format->palette) <= -1)
ErrSdl();

4
Source/DiabloUI/diabloui.cpp

@ -635,7 +635,7 @@ void LoadBackgroundArt(const char *pszFile, int frames)
BlackPalette();
SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000);
if (DiabloUiSurface() == pal_surface)
if (DiabloUiSurface() == PalSurface)
BltFast(nullptr, nullptr);
RenderPresent();
}
@ -672,7 +672,7 @@ void UiFadeIn()
SetFadeLevel(fadeValue);
}
if (DiabloUiSurface() == pal_surface)
if (DiabloUiSurface() == PalSurface)
BltFast(nullptr, nullptr);
RenderPresent();
}

2
Source/DiabloUI/diabloui.h

@ -86,7 +86,7 @@ inline SDL_Surface *DiabloUiSurface()
// to an off-screen surface first to avoid flickering / tearing.
if ((output_surface->flags & SDL_HWSURFACE) != 0
&& (output_surface->flags & SDL_DOUBLEBUF) == 0) {
return pal_surface;
return PalSurface;
}
#endif

33
Source/dx.cpp

@ -35,9 +35,12 @@ unsigned int pal_surface_palette_version = 0;
SDLSurfaceUniquePtr RendererTextureSurface;
/** 8-bit surface that we render to */
SDL_Surface *pal_surface;
SDL_Surface *PalSurface;
namespace {
SDLSurfaceUniquePtr PinnedPalSurface;
} // namespace
/** Whether we render directly to the screen surface, i.e. `pal_surface == GetOutputSurface()` */
/** Whether we render directly to the screen surface, i.e. `PalSurface == GetOutputSurface()` */
bool RenderDirectlyToOutputSurface;
namespace {
@ -68,26 +71,24 @@ void CreateBackBuffer()
{
if (CanRenderDirectlyToOutputSurface()) {
Log("{}", "Will render directly to the SDL output surface");
pal_surface = GetOutputSurface();
PalSurface = GetOutputSurface();
RenderDirectlyToOutputSurface = true;
} else {
pal_surface = SDL_CreateRGBSurfaceWithFormat(
PinnedPalSurface = SDLWrap::CreateRGBSurfaceWithFormat(
/*flags=*/0,
/*width=*/gnScreenWidth,
/*height=*/gnScreenHeight,
/*depth=*/8,
SDL_PIXELFORMAT_INDEX8);
if (pal_surface == nullptr) {
ErrSdl();
}
PalSurface = PinnedPalSurface.get();
}
#ifndef USE_SDL1
// In SDL2, `pal_surface` points to the global `palette`.
if (SDL_SetSurfacePalette(pal_surface, Palette.get()) < 0)
// In SDL2, `PalSurface` points to the global `palette`.
if (SDL_SetSurfacePalette(PalSurface, Palette.get()) < 0)
ErrSdl();
#else
// In SDL1, `pal_surface` owns its palette and we must update it every
// In SDL1, `PalSurface` owns its palette and we must update it every
// time the global `palette` is changed. No need to do anything here as
// the global `palette` doesn't have any colors set yet.
#endif
@ -189,7 +190,7 @@ Surface GlobalBackBuffer()
return Surface();
}
return Surface(pal_surface, SDL_Rect { 0, 0, gnScreenWidth, gnScreenHeight });
return Surface(PalSurface, SDL_Rect { 0, 0, gnScreenWidth, gnScreenHeight });
}
void dx_cleanup()
@ -202,10 +203,10 @@ void dx_cleanup()
sgdwLockCount = 0;
MemCrit.unlock();
if (pal_surface == nullptr)
if (PalSurface == nullptr)
return;
SDL_FreeSurface(pal_surface);
pal_surface = nullptr;
PalSurface = nullptr;
PinnedPalSurface = nullptr;
Palette = nullptr;
RendererTextureSurface = nullptr;
#ifndef USE_SDL1
@ -247,7 +248,7 @@ void BltFast(SDL_Rect *srcRect, SDL_Rect *dstRect)
{
if (RenderDirectlyToOutputSurface)
return;
Blit(pal_surface, srcRect, dstRect);
Blit(PalSurface, srcRect, dstRect);
}
void Blit(SDL_Surface *src, SDL_Rect *srcRect, SDL_Rect *dstRect)
@ -342,7 +343,7 @@ void RenderPresent()
ErrSdl();
}
if (RenderDirectlyToOutputSurface)
pal_surface = GetOutputSurface();
PalSurface = GetOutputSurface();
LimitFrameRate();
#endif
}

2
Source/dx.h

@ -9,7 +9,7 @@
namespace devilution {
/** Whether we render directly to the screen surface, i.e. `pal_surface == GetOutputSurface()` */
/** Whether we render directly to the screen surface, i.e. `PalSurface == GetOutputSurface()` */
extern bool RenderDirectlyToOutputSurface;
Surface GlobalBackBuffer();

2
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.get(), system_palette, first, ncolor) < 0) {
if (SDLC_SetSurfaceAndPaletteColors(PalSurface, Palette.get(), system_palette, first, ncolor) < 0) {
ErrSdl();
}
pal_surface_palette_version++;

6
Source/scrollrt.cpp

@ -1552,14 +1552,14 @@ void CalcViewportGeometry()
tileRows++; // Cover lower edge saw tooth, right edge accounted for in scrollrt_draw()
}
extern SDL_Surface *pal_surface;
extern SDL_Surface *PalSurface;
void ClearScreenBuffer()
{
lock_buf(3);
assert(pal_surface != nullptr);
SDL_FillRect(pal_surface, nullptr, 0);
assert(PalSurface != nullptr);
SDL_FillRect(PalSurface, nullptr, 0);
unlock_buf(3);
}

2
Source/utils/display.h

@ -23,7 +23,7 @@ extern SDLTextureUniquePtr texture;
#endif
extern SDLPaletteUniquePtr Palette;
extern SDL_Surface *pal_surface;
extern SDL_Surface *PalSurface;
extern unsigned int pal_surface_palette_version;
#ifdef USE_SDL1

Loading…
Cancel
Save