Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in palette_update code #14

Open
azihassan opened this issue Oct 12, 2024 · 1 comment
Open

Crash in palette_update code #14

azihassan opened this issue Oct 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@azihassan
Copy link
Owner

azihassan commented Oct 12, 2024

Recent builds cause the game to crash after the splash screen. The culprit seems to be either palette_update or the underlying SDLC_SetSurfaceAndPaletteColors function.

In the previous release, SDLC_SetSurfaceAndPaletteColors was causing an unrelated error (failure to read an mpq from /vmu). The return SDL_SetPalette(surface, SDL_LOGPAL, colors, firstcolor, ncolors) - 1; was returning -1 and triggering the < 0 check in palette_update:

	if (SDLC_SetSurfaceAndPaletteColors(PalSurface, Palette.get(), system_palette.data(), first, ncolor) < 0) {
		ErrSdl(); //<<< here
	}

I'm assuming that ErrSdl displays the most recent error, which was caused by a normal MPQ search path anomaly (no MPQs on the VMU). But it gets triggered because SDL_SetPalette probably returned 0 and didn't change whatever error state ErrSdl pulls errors from. Removing - 1 caused the game to crash (or freeze, I don't remember) on real hardware, and skipping the SDL_SetPalette call altogether allowed it to run normally. I'm assuming it's because the SDL_SetColors call above it already updates the palette internally when 8 bpp and SDL_HWPALETTE are enabled (emphasis mine):

Palettized (8-bit) screen surfaces with the SDL_HWPALETTE flag have two palettes, a logical palette that is used for mapping blits to/from the surface and a physical palette (that determines how the hardware will map the colors to the display). SDL_SetColors modifies both palettes (if present), and is equivalent to calling SDL_SetPalette with the flags set to (SDL_LOGPAL | SDL_PHYSPAL).

However with the fork and SDL port updated to the latest version, this no longer works.

@azihassan
Copy link
Owner Author

Thanks @glebm. I tested it but the issue is very flaky. Sometimes it works when there are logs and sometimes not, it hangs on Flycast but reboots the console, etc.

I found a similar issue that was solved by disabling LTO. Doing it with set(DISABLE_LTO ON) was not enough, so I specifically requested it by manually setting -flto=none. I'm gonna have to recompile in verbose mode to see what's going on

@azihassan azihassan moved this to In progress in Devilutionx Dreamcast port Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In progress
Development

No branches or pull requests

1 participant