Merge pull request #5490 from maron2000/ttf_fullscr_fix

Fix crash when switching from fullscreen to window mode in TTF output
This commit is contained in:
Jonathan Campbell 2025-02-12 11:07:54 -08:00 committed by GitHub
commit 9e08fa5395
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 17 deletions

View File

@ -2659,9 +2659,9 @@ void GFX_SwitchFullScreen(void)
if (ttf.inUse) { if (ttf.inUse) {
if (ttf.fullScrn) { if (ttf.fullScrn) {
sdl.desktop.fullscreen = false; sdl.desktop.fullscreen = false;
if (lastfontsize>0) //if (lastfontsize>0)
OUTPUT_TTF_Select(lastfontsize); // OUTPUT_TTF_Select(lastfontsize); /* certain lastfontsize will crash DOSBox-X */
else //else
OUTPUT_TTF_Select(1); OUTPUT_TTF_Select(1);
resetFontSize(); resetFontSize();
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU #if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
@ -2692,6 +2692,8 @@ void GFX_SwitchFullScreen(void)
} }
SDL_SetWindowPosition(sdl.window, bx, by); SDL_SetWindowPosition(sdl.window, bx, by);
} }
else if(posx == -2 && posy == -2)
SDL_SetWindowPosition(sdl.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
#endif #endif
resetreq = true; resetreq = true;
GFX_ResetScreen(); GFX_ResetScreen();

View File

@ -861,7 +861,7 @@ resize1:
GFX_SelectFontByPoints(curSize); GFX_SelectFontByPoints(curSize);
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU #if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
if (!ttf.fullScrn && menu_gui && menu.toggle && menuwidth_atleast(ttf.cols*ttf.width+ttf.offX*2+GetSystemMetrics(SM_CXBORDER)*2)>0) { if (!ttf.fullScrn && menu_gui && menu.toggle && menuwidth_atleast(ttf.cols*ttf.width+ttf.offX*2+GetSystemMetrics(SM_CXBORDER)*2)>0) {
if (ttf.cols*ttf.width > maxWidth || ttf.lins*ttf.height > maxHeight) E_Exit("Cannot accommodate a window for %dx%d", ttf.lins, ttf.cols); if (ttf.cols*ttf.width > maxWidth || ttf.lins*ttf.height > maxHeight) E_Exit("Cannot accommodate a window for %dx%d", ttf.cols, ttf.lins);
curSize++; curSize++;
goto resize1; goto resize1;
} }
@ -880,7 +880,7 @@ resize2:
GFX_SelectFontByPoints(curSize); GFX_SelectFontByPoints(curSize);
goto resize2; goto resize2;
} }
E_Exit("Cannot accommodate a window for %dx%d", ttf.lins, ttf.cols); E_Exit("Cannot accommodate a window for %dx%d", ttf.cols, ttf.lins);
} }
if (ttf.SDL_font && ttf.width) { if (ttf.SDL_font && ttf.width) {
int widthb, widthm, widthx, width0, width1, width9; int widthb, widthm, widthx, width0, width1, width9;
@ -1412,7 +1412,6 @@ void ttf_setlines(int cols, int lins) {
} }
void ttf_switch_on(bool ss=true) { void ttf_switch_on(bool ss=true) {
if(!finish_prepare) return;
if ((ss&&ttfswitch)||(!ss&&switch_output_from_ttf)) { if ((ss&&ttfswitch)||(!ss&&switch_output_from_ttf)) {
checkcol = 0; checkcol = 0;
if (strcmp(RunningProgram, "LOADLIN")) { if (strcmp(RunningProgram, "LOADLIN")) {
@ -1432,7 +1431,7 @@ void ttf_switch_on(bool ss=true) {
bool OpenGL_using(void), gl = OpenGL_using(); bool OpenGL_using(void), gl = OpenGL_using();
(void)gl; // unused var warning (void)gl; // unused var warning
#if defined(WIN32) && !defined(C_SDL2) #if defined(WIN32) && !defined(C_SDL2)
change_output(0); // call OUTPUT_SURFACE_Select() to initialize output before enabling TTF output on Windows builds //change_output(0); // call OUTPUT_SURFACE_Select() to initialize output before enabling TTF output on Windows builds
#endif #endif
change_output(10); // call OUTPUT_TTF_Select() change_output(10); // call OUTPUT_TTF_Select()
SetVal("sdl", "output", "ttf"); SetVal("sdl", "output", "ttf");

View File

@ -87,6 +87,8 @@ void makestdcp950table(), makeseacp951table();
#if defined(USE_TTF) #if defined(USE_TTF)
void ttf_switch_on(bool ss = true), ttf_switch_off(bool ss = true); void ttf_switch_on(bool ss = true), ttf_switch_off(bool ss = true);
void ttf_setlines(int cols, int lins);
void ttf_reset();
#endif #endif
extern VideoModeBlock* CurMode; extern VideoModeBlock* CurMode;
@ -827,6 +829,14 @@ void showWelcome(Program *shell) {
bool finish_prepare = false; bool finish_prepare = false;
void DOS_Shell::Prepare(void) { void DOS_Shell::Prepare(void) {
if (this == first_shell) { if (this == first_shell) {
#if defined(USE_TTF)
if(CurMode->type == M_TEXT) ttf_switch_on(true); // Initialization completed, M_TEXT modes can switch to TTF mode from now on.
if(ttf.inUse) {
int cols = static_cast<Section_prop*>(control->GetSection("ttf"))->Get_int("cols");
int lins = static_cast<Section_prop*>(control->GetSection("ttf"))->Get_int("lins");
if(cols || lins) ttf_setlines(cols, lins);
}
#endif
const char* layoutname = DOS_GetLoadedLayout(); const char* layoutname = DOS_GetLoadedLayout();
if(layoutname == NULL) { if(layoutname == NULL) {
int32_t cp = dos.loaded_codepage; int32_t cp = dos.loaded_codepage;
@ -834,11 +844,11 @@ void DOS_Shell::Prepare(void) {
toSetCodePage(NULL, cp, -1); toSetCodePage(NULL, cp, -1);
} }
Section_prop *section = static_cast<Section_prop *>(control->GetSection("dosbox")); Section_prop *section = static_cast<Section_prop *>(control->GetSection("dosbox"));
if (section->Get_bool("startbanner")&&!control->opt_fastlaunch) if(section->Get_bool("startbanner") && !control->opt_fastlaunch)
showWelcome(this); showWelcome(NULL);
else if ((CurMode->type==M_TEXT || IS_PC98_ARCH) && ANSI_SYS_installed()) else if((CurMode->type == M_TEXT || IS_PC98_ARCH) && ANSI_SYS_installed())
WriteOut("\033[2J"); WriteOut("\033[2J");
if (!countryNo) { if (!countryNo) {
#if defined(WIN32) #if defined(WIN32)
char buffer[128]; char buffer[128];
#endif #endif
@ -867,7 +877,7 @@ void DOS_Shell::Prepare(void) {
bool zdirpath = section->Get_bool("drive z expand path"); bool zdirpath = section->Get_bool("drive z expand path");
std::string layout = section->Get_string("keyboardlayout"); std::string layout = section->Get_string("keyboardlayout");
strcpy(config_data, ""); strcpy(config_data, "");
section = static_cast<Section_prop *>(control->GetSection("config")); section = static_cast<Section_prop *>(control->GetSection("config"));
if ((section!=NULL&&!control->opt_noconfig)||control->opt_langcp) { if ((section!=NULL&&!control->opt_noconfig)||control->opt_langcp) {
char *countrystr = (char *)section->Get_string("country"), *r=strchr(countrystr, ','); char *countrystr = (char *)section->Get_string("country"), *r=strchr(countrystr, ',');
int country = 0; int country = 0;
@ -890,7 +900,6 @@ void DOS_Shell::Prepare(void) {
} }
if(!chinasea)makestdcp950table(); if(!chinasea)makestdcp950table();
if(chinasea) makeseacp951table(); if(chinasea) makeseacp951table();
runRescan("-A -Q");
const char * extra = section->data.c_str(); const char * extra = section->data.c_str();
if (extra&&!control->opt_securemode&&!control->SecureMode()&&!control->opt_noconfig) { if (extra&&!control->opt_securemode&&!control->SecureMode()&&!control->opt_noconfig) {
std::string vstr; std::string vstr;
@ -954,6 +963,8 @@ void DOS_Shell::Prepare(void) {
strcat(config_data, section->Get_string("rem")); strcat(config_data, section->Get_string("rem"));
strcat(config_data, "\r\n"); strcat(config_data, "\r\n");
} }
if(dos.loaded_codepage == 932) toSetCodePage(this, 932, -1); // Workaround for corrupted box-drawing characters
runRescan("-A -Q");
internal_program = true; internal_program = true;
VFILE_Register("AUTOEXEC.BAT",(uint8_t *)autoexec_data,(uint32_t)strlen(autoexec_data)); VFILE_Register("AUTOEXEC.BAT",(uint8_t *)autoexec_data,(uint32_t)strlen(autoexec_data));
VFILE_Register("CONFIG.SYS",(uint8_t *)config_data,(uint32_t)strlen(config_data)); VFILE_Register("CONFIG.SYS",(uint8_t *)config_data,(uint32_t)strlen(config_data));
@ -988,9 +999,6 @@ void DOS_Shell::Prepare(void) {
//initcodepagefont(); //initcodepagefont();
//dos.loaded_codepage=cp; //dos.loaded_codepage=cp;
finish_prepare = true; finish_prepare = true;
#if defined(USE_TTF)
if(CurMode->type == M_TEXT) ttf_switch_on(true); // Initialization completed, M_TEXT modes can switch to TTF mode from now on.
#endif
} }
#if (defined(WIN32) && !defined(HX_DOS) || defined(LINUX) && C_X11 || defined(MACOSX)) && (defined(C_SDL2) || defined(SDL_DOSBOX_X_SPECIAL)) #if (defined(WIN32) && !defined(HX_DOS) || defined(LINUX) && C_X11 || defined(MACOSX)) && (defined(C_SDL2) || defined(SDL_DOSBOX_X_SPECIAL))
if (enableime) SetIMPosition(); if (enableime) SetIMPosition();
@ -1279,7 +1287,7 @@ public:
} }
//#endif /* (WIN32) && (USE_TTF) */ //#endif /* (WIN32) && (USE_TTF) */
#endif // 0 #endif // 0
if (addexit) autoexec[i++].Install("exit"); if (addexit) autoexec[i++].Install("exit");
assert(i <= 17); /* FIXME: autoexec[] should not be fixed size */ assert(i <= 17); /* FIXME: autoexec[] should not be fixed size */