Skip to content

Commit

Permalink
Factor out FreeSurfaceContents, and handle surface20 more defensively
Browse files Browse the repository at this point in the history
This is a step towards making it possible to use the same SDL12_Surface
for the video surface at all times, and only reallocating its underlying
SDL 2 SDL_Surface.

Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv committed Jul 20, 2023
1 parent e6c6491 commit 42f3bd2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/SDL12_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,19 @@ SDL_WasInit(Uint32 sdl12flags)
return InitFlags20to12(SDL20_WasInit(sdl20flags)) | extraflags;
}

static void
FreeSurfaceContents(SDL12_Surface *surface12)
{
if (surface12->surface20) {
SDL20_FreeSurface(surface12->surface20);
surface12->surface20 = NULL;
}
if (surface12->format) {
SDL20_free(surface12->format->palette);
SDL20_free(surface12->format);
surface12->format = NULL;
}
}

static SDL12_Surface *EndVidModeCreate(void);
static void
Expand Down Expand Up @@ -5198,11 +5211,7 @@ SDL_FreeSurface(SDL12_Surface *surface12)
surface12->refcount--;
if (surface12->refcount)
return;
SDL20_FreeSurface(surface12->surface20);
if (surface12->format) {
SDL20_free(surface12->format->palette);
SDL20_free(surface12->format);
}
FreeSurfaceContents(surface12);
SDL20_free(surface12);
}
}
Expand Down

0 comments on commit 42f3bd2

Please sign in to comment.