Make sure the blit mapping is cleared when undoing RLE encoding
This fixes a crash if a surface is RLE encoded, then locked and unlocked.
We also mark the surface as no longer needing to be locked after undoing RLE encoding
diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c
index 2f0c680..3d2df5a 100644
--- a/src/video/SDL_RLEaccel.c
+++ b/src/video/SDL_RLEaccel.c
@@ -89,6 +89,7 @@
#include "SDL_sysvideo.h"
#include "SDL_surface_c.h"
+#include "SDL_pixels_c.h"
#include "SDL_RLEaccel_c.h"
#define PIXEL_COPY(to, from, len, bpp) \
@@ -1385,6 +1386,8 @@
SDL_free(surface->map.data);
surface->map.data = NULL;
+ SDL_InvalidateMap(&surface->map);
+
SDL_UpdateSurfaceLockFlag(surface);
}
}
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 7a53b5c..99c1318 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -50,7 +50,9 @@
void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface)
{
- if (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ // We need to mark the surface as needing unlock while locked
+ if ((surface->flags & SDL_SURFACE_LOCKED) ||
+ (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL)) {
surface->flags |= SDL_SURFACE_LOCK_NEEDED;
} else {
surface->flags &= ~SDL_SURFACE_LOCK_NEEDED;
@@ -1726,7 +1728,6 @@
// Perform the lock
if (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
SDL_UnRLESurface(surface);
- surface->flags |= SDL_SURFACE_LOCK_NEEDED;
}
#endif
}
@@ -1734,6 +1735,7 @@
// Increment the surface lock count, for recursive locks
++surface->locked;
surface->flags |= SDL_SURFACE_LOCKED;
+ SDL_UpdateSurfaceLockFlag(surface);
// Ready to go..
return true;
@@ -1754,6 +1756,7 @@
}
surface->flags &= ~SDL_SURFACE_LOCKED;
+ SDL_UpdateSurfaceLockFlag(surface);
}
static bool SDL_FlipSurfaceHorizontal(SDL_Surface *surface)