sdl12-compat: Handle applications manually freeing surface pixels

From c6e6bc68aac5f46e393ca31560fd0e976bf635d2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 2 Apr 2026 10:39:27 -0700
Subject: [PATCH] Handle applications manually freeing surface pixels

Fixes https://github.com/libsdl-org/sdl12-compat/issues/385
---
 src/SDL12_compat.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 01fab23aa..3ea7f640f 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1475,6 +1475,9 @@ static QuirkEntryType quirks[] = {
     {"Jamestown-x86", "SDL12COMPAT_OPENGL_SCALING", "0"},
     {"Jamestown-amd64", "SDL12COMPAT_OPENGL_SCALING", "0"},
 
+    /* Sacred Gold manually frees SDL surface pixels */
+    {"sacred", "SDL_SURFACE_MALLOC", "1"},
+
 #else
     /* TODO: Add any quirks needed for this system. */
 
@@ -2934,6 +2937,9 @@ static void
 FreeSurfaceContents(SDL12_Surface *surface12)
 {
     if (surface12->surface20) {
+        if (surface12->pixels == NULL) {
+            surface12->surface20->pixels = NULL;
+        }
         SDL20_FreeSurface(surface12->surface20);
         surface12->surface20 = NULL;
     }