Opened 6 weeks ago
Last modified 6 weeks ago
#17280 new defect
BACKENDS/MADS: Nebular: Background rendering issues with surfacesdl (SDL3)
| Reported by: | dwatteau | Owned by: | |
|---|---|---|---|
| Priority: | high | Component: | Graphics |
| Version: | Keywords: | ||
| Cc: | Game: | Rex Nebular |
Description
Game version:
User picked target 'nebular' (engine ID 'mads', game ID 'nebular')... Running Rex Nebular and the Cosmic Gender Bender (DOS/English) section1.hag: 6f725eb38660de8af31ec7cdd628d615, 927222 bytes.
env: macOS 26.7 (aarch64), Apple clang 21, SDL 3.4.16 (from Homebrew).
ScummVM release: current Git HEAD (454c594583003303b903d4619867b32db8394c72).
How to reproduce:
- build against SDL3, with
--prefer-sdl3 - have SDL Surface as the default renderer
- start a new game of Rex Nebular
Problem: game backgrounds in the first scene are wrong (see attached screenshot).
It's fine if I switch back to the OpenGL renderer.
Can't say if it's an engine bug or a backend bug, but SDL Surface is usually OK with most other games.
(Also attaching the configuration file.)
Attachments (2)
Change History (6)
by , 6 weeks ago
| Attachment: | scummvm-nebular-00000.png added |
|---|
comment:1 by , 6 weeks ago
| Priority: | normal → high |
|---|
Bumping priority as the next release is nearby, and I think we have several ports where the OpenGL renderer isn't the default one.
comment:2 by , 6 weeks ago
| Component: | Engine: MADS → Graphics |
|---|---|
| Summary: | MADS: Nebular: Background rendering issues with surfacesdl → BACKENDS/MADS: Nebular: Background rendering issues with surfacesdl (SDL3) |
comment:3 by , 6 weeks ago
I'm moving this to the BACKENDS graphics area, because after some Claude analysis it looks like the MADS engine may just be hitting a backend issue with SDL3.
In the SDL_SetColors() path, SDL3 builds it were always calling SDL_CreateSurfacePalette() again. Claude produced this fix, then, which fixes the bug for me.
BACKENDS: SURFACESDL: Fix partial palette updates with SDL3 (Trac#17280)
SDL_CreateSurfacePalette() replaces any existing surface palette with a
new one where all entries are white [1], so each SDL_SetColors() call
wiped every color outside the updated range. Games doing partial palette
updates, such as MADS with its palette cycling, got white backgrounds.
Reuse the existing palette instead.
Also, when saving a screenshot, just read the existing palette instead
of replacing it, for consistency.
[1]: https://wiki.libsdl.org/SDL3/SDL_CreateSurfacePalette#remarks
Assisted-by: Claude:claude-opus-5-5
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index ad7bc1a82fd..50abed5e0cd 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -1620,7 +1620,7 @@ bool SurfaceSdlGraphicsManager::saveScreenshot(const Common::Path &filename) con
bool success;
#if SDL_VERSION_ATLEAST(3, 0, 0)
- SDL_Palette *sdlPalette = SDL_CreateSurfacePalette(_hwScreen);
+ SDL_Palette *sdlPalette = SDL_GetSurfacePalette(_hwScreen);
#else
SDL_Palette *sdlPalette = _hwScreen->format->palette;
#endif
@@ -3202,7 +3202,9 @@ void SurfaceSdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrect
int SurfaceSdlGraphicsManager::SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
#if SDL_VERSION_ATLEAST(3, 0, 0)
- SDL_Palette *palette = SDL_CreateSurfacePalette(surface);
+ SDL_Palette *palette = SDL_GetSurfacePalette(surface);
+ if (!palette)
+ palette = SDL_CreateSurfacePalette(surface);
if (palette) {
return !SDL_SetPaletteColors(palette, colors, firstcolor, ncolors) ? 1 : 0;
}
and then, while iterating through this, I was getting random SDL_BlitSurface failed: Parameter 'src' is invalid! warning windows from SDL. It then suggested the following change as well:
BACKENDS: SURFACESDL: Properly initialize `_numDirtyRects`
The first screen update of a newly created manager could blit garbage
rects from a screen surface that wasn't allocated yet, causing random
"SDL_BlitSurface failed: Parameter 'src' is invalid!" startup errors.
Assisted-by: Claude:claude-opus-5-5
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 50abed5e0cd..7ed441a6d42 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -190,7 +190,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
#endif
_transactionMode(kTransactionNone),
_scalerPlugins(ScalerMan.getPlugins()), _scalerPlugin(nullptr), _scaler(nullptr),
- _needRestoreAfterOverlay(false), _isInOverlayPalette(false), _isDoubleBuf(false), _prevForceRedraw(false), _numPrevDirtyRects(0),
+ _needRestoreAfterOverlay(false), _isInOverlayPalette(false), _isDoubleBuf(false), _prevForceRedraw(false), _numDirtyRects(0), _numPrevDirtyRects(0),
_prevCursorNeedsRedraw(false),
_mouseKeyColor(0), _disableMouseKeyColor(false) {
I'm including this here for investigation purposes, but graphics area clearly is a place where I'd rather not submit any change myself, be it AI-assisted or not :D
comment:4 by , 6 weeks ago
I checked internally with the team, and confirmed that none of the backends use SDL3 yet, since it's still outstanding porting SDL3_Net. So it's not a release blocker.

Wrong background rendering with surfacesdl renderer