From 473efcf53cf1536190c5f3858c348336538df53e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 2 Apr 2026 10:36:56 -0700
Subject: [PATCH] Added a hint "SDL_SURFACE_MALLOC" to disable aligned surface
allocation
This is needed for sdl12-compat, where all surfaces were not aligned.
(cherry picked from commit dd01e096e9c5d8a58977a7506e5c1cbae8def0ea)
---
src/video/SDL_surface.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 1f836bf2175c4..7ef72f5e6e479 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -20,6 +20,7 @@
*/
#include "../SDL_internal.h"
+#include "SDL_hints.h"
#include "SDL_video.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
@@ -153,13 +154,17 @@ SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height,
return NULL;
}
- surface->pixels = SDL_SIMDAlloc(size);
+ if (SDL_GetHintBoolean("SDL_SURFACE_MALLOC", SDL_FALSE)) {
+ surface->pixels = SDL_malloc(size);
+ } else {
+ surface->flags |= SDL_SIMD_ALIGNED;
+ surface->pixels = SDL_SIMDAlloc(size);
+ }
if (!surface->pixels) {
SDL_FreeSurface(surface);
SDL_OutOfMemory();
return NULL;
}
- surface->flags |= SDL_SIMD_ALIGNED;
/* This is important for bitmaps */
SDL_memset(surface->pixels, 0, size);
}