Fix mapper not rendering anything on SDL2/Windows

This commit is contained in:
aybe
2025-08-20 23:24:55 +02:00
parent cbdc94cc66
commit 7441b55e2b
3 changed files with 22 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ Next version
- Fix errors when initializing fluidsynth (maron2000)
- PC-98: Redraw the function keys after updating them (bobsayshilol)
- Do not carriage return with a single LF('\n') (maron2000)
- Fix mapper not rendering anything on SDL2/Windows (aybe)
2025.05.03
- Show TURBO status in title bar. (maron2000)

View File

@@ -1868,6 +1868,9 @@ void SDL1_hax_SetMenu(HMENU menu) {
extern "C" void SDL1_hax_SetMenu(HMENU menu);
#endif
/**
* NOTE: this function can make a SDL_Surface become invalid (e.g. mapper, Windows)
*/
void DOSBox_SetMenu(DOSBoxMenu &altMenu) {
#if DOSBOXMENU_TYPE == DOSBOXMENU_SDLDRAW
/* nothing to do */

View File

@@ -3901,7 +3901,10 @@ static void DrawButtons(void) {
SDL_BlitSurface(mapper.draw_surface, NULL, mapper.draw_surface_nonpaletted, NULL);
SDL_BlitScaled(mapper.draw_surface_nonpaletted, NULL, mapper.surface, &mapper.draw_rect);
// SDL_BlitSurface(mapper.draw_surface, NULL, mapper.surface, NULL);
SDL_UpdateWindowSurface(mapper.window);
if (SDL_UpdateWindowSurface(mapper.window) != 0)
{
E_Exit("Couldn't update window surface for mapper: %s", SDL_GetError());
}
#else
SDL_UnlockSurface(mapper.surface);
SDL_Flip(mapper.surface);
@@ -5308,6 +5311,18 @@ void update_all_shortcuts() {
if (ev != NULL) ev->update_menu_shortcut();
}
void UpdateMapperSurface()
{
mapper.surface = SDL_GetWindowSurface(mapper.window);
if (mapper.surface == nullptr)
{
const auto error = SDL_GetError();
E_Exit("Could not initialize video mode for mapper: %s", error);
}
}
void MAPPER_RunInternal() {
MAPPER_ReleaseAllKeys();
@@ -5361,8 +5376,7 @@ void MAPPER_RunInternal() {
GFX_SetResizeable(false);
mapper.window = OpenGL_using() ? GFX_SetSDLWindowMode(640,480,SCREEN_OPENGL) : GFX_SetSDLSurfaceWindow(640,480);
if (mapper.window == NULL) E_Exit("Could not initialize video mode for mapper: %s",SDL_GetError());
mapper.surface=SDL_GetWindowSurface(mapper.window);
if (mapper.surface == NULL) E_Exit("Could not initialize video mode for mapper: %s",SDL_GetError());
UpdateMapperSurface();
mapper.draw_surface=SDL_CreateRGBSurface(0,640,480,8,0,0,0,0);
// Needed for SDL_BlitScaled
mapper.draw_surface_nonpaletted=SDL_CreateRGBSurface(0,640,480,32,0x0000ff00,0x00ff0000,0xff000000,0);
@@ -5396,6 +5410,7 @@ void MAPPER_RunInternal() {
#endif
ApplyPreventCap();
UpdateMapperSurface(); // update again because of DOSBox_SetMenu
#if defined(MACOSX)
macosx_reload_touchbar();
#endif