sdl12-compat: SDL_CreateRGBSurface: Don't assert SDL_PREALLOC not set on 0-sized surface

From 44b1e1f234465248ee7e04562e67d452d63714a8 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Tue, 29 Jul 2025 16:14:19 +0800
Subject: [PATCH] SDL_CreateRGBSurface: Don't assert SDL_PREALLOC not set on
 0-sized surface
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

SDL_CreateRGBSurface currently asserts that SDL_PREALLOC is not set. However,
if the surface is empty (width or height are zero), then it doesn't matter
if pixels is valid.

SDL2 does allocate an "empty" pixels, and so doesn't set SDL_PREALLOCATED, but
SDL3 (including via sdl2compat) doesn't, leaving the empty SDL_Surface with
SDL_PREALLOCATED (so it doesn't try to free the NULL pointer).

This _could_ be worked around in sdl2compat, but the SDL3/sdl2compat behaviour
does make sense, and it's only the zealous assertion here which breaks.

Civilization: Call To Power triggers this by trying to create a bunch of 0×0
surfaces at startup, and is fixed by this patch.

Fixes: 13efe605cc42 ("Factor out enough of SDL_CreateRGBSurface to create surfaces in-place")
---
 src/SDL12_compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 53ef8da43..1d309a2e6 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -5487,7 +5487,7 @@ SDL_CreateRGBSurface(Uint32 flags12, int width, int height, int depth, Uint32 Rm
         return NULL;
     }
 
-    SDL_assert((surface12->flags & ~(SDL12_SRCCOLORKEY|SDL12_SRCALPHA)) == 0);  /* shouldn't have prealloc, rleaccel, or dontfree. */
+    SDL_assert(!(width && height) || ((surface12->flags & ~(SDL12_SRCCOLORKEY|SDL12_SRCALPHA))) == 0);  /* shouldn't have prealloc, rleaccel, or dontfree. */
     Surface12SetMasks(surface12, Rmask, Gmask, Bmask, Amask);
     return surface12;
 }