Skip to content

Commit

Permalink
Merge pull request #5490 from maron2000/ttf_fullscr_fix
Browse files Browse the repository at this point in the history
Fix crash when switching from fullscreen to window mode in TTF output
  • Loading branch information
joncampbell123 authored Feb 12, 2025
2 parents 928c28f + 5a55103 commit 9e08fa5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2659,9 +2659,9 @@ void GFX_SwitchFullScreen(void)
if (ttf.inUse) {
if (ttf.fullScrn) {
sdl.desktop.fullscreen = false;
if (lastfontsize>0)
OUTPUT_TTF_Select(lastfontsize);
else
//if (lastfontsize>0)
// OUTPUT_TTF_Select(lastfontsize); /* certain lastfontsize will crash DOSBox-X */
//else
OUTPUT_TTF_Select(1);
resetFontSize();
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU
Expand Down Expand Up @@ -2692,6 +2692,8 @@ void GFX_SwitchFullScreen(void)
}
SDL_SetWindowPosition(sdl.window, bx, by);
}
else if(posx == -2 && posy == -2)
SDL_SetWindowPosition(sdl.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
#endif
resetreq = true;
GFX_ResetScreen();
Expand Down
7 changes: 3 additions & 4 deletions src/output/output_ttf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void OUTPUT_TTF_Select(int fsize) {
GFX_SelectFontByPoints(curSize);
#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.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++;
goto resize1;
}
Expand All @@ -880,7 +880,7 @@ void OUTPUT_TTF_Select(int fsize) {
GFX_SelectFontByPoints(curSize);
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) {
int widthb, widthm, widthx, width0, width1, width9;
Expand Down Expand Up @@ -1412,7 +1412,6 @@ void ttf_setlines(int cols, int lins) {
}

void ttf_switch_on(bool ss=true) {
if(!finish_prepare) return;
if ((ss&&ttfswitch)||(!ss&&switch_output_from_ttf)) {
checkcol = 0;
if (strcmp(RunningProgram, "LOADLIN")) {
Expand All @@ -1432,7 +1431,7 @@ void ttf_switch_on(bool ss=true) {
bool OpenGL_using(void), gl = OpenGL_using();
(void)gl; // unused var warning
#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
change_output(10); // call OUTPUT_TTF_Select()
SetVal("sdl", "output", "ttf");
Expand Down
28 changes: 18 additions & 10 deletions src/shell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void makestdcp950table(), makeseacp951table();

#if defined(USE_TTF)
void ttf_switch_on(bool ss = true), ttf_switch_off(bool ss = true);
void ttf_setlines(int cols, int lins);
void ttf_reset();
#endif
extern VideoModeBlock* CurMode;

Expand Down Expand Up @@ -827,18 +829,26 @@ void showWelcome(Program *shell) {
bool finish_prepare = false;
void DOS_Shell::Prepare(void) {
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();
if(layoutname == NULL) {
int32_t cp = dos.loaded_codepage;
Bitu keyb_error = DOS_LoadKeyboardLayout("us", 437, "auto");
toSetCodePage(NULL, cp, -1);
}
Section_prop *section = static_cast<Section_prop *>(control->GetSection("dosbox"));
if (section->Get_bool("startbanner")&&!control->opt_fastlaunch)
showWelcome(this);
else if ((CurMode->type==M_TEXT || IS_PC98_ARCH) && ANSI_SYS_installed())
if(section->Get_bool("startbanner") && !control->opt_fastlaunch)
showWelcome(NULL);
else if((CurMode->type == M_TEXT || IS_PC98_ARCH) && ANSI_SYS_installed())
WriteOut("\033[2J");
if (!countryNo) {
if (!countryNo) {
#if defined(WIN32)
char buffer[128];
#endif
Expand Down Expand Up @@ -867,7 +877,7 @@ void DOS_Shell::Prepare(void) {
bool zdirpath = section->Get_bool("drive z expand path");
std::string layout = section->Get_string("keyboardlayout");
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) {
char *countrystr = (char *)section->Get_string("country"), *r=strchr(countrystr, ',');
int country = 0;
Expand All @@ -890,7 +900,6 @@ void DOS_Shell::Prepare(void) {
}
if(!chinasea)makestdcp950table();
if(chinasea) makeseacp951table();
runRescan("-A -Q");
const char * extra = section->data.c_str();
if (extra&&!control->opt_securemode&&!control->SecureMode()&&!control->opt_noconfig) {
std::string vstr;
Expand Down Expand Up @@ -954,6 +963,8 @@ void DOS_Shell::Prepare(void) {
strcat(config_data, section->Get_string("rem"));
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;
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));
Expand Down Expand Up @@ -988,9 +999,6 @@ void DOS_Shell::Prepare(void) {
//initcodepagefont();
//dos.loaded_codepage=cp;
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 (enableime) SetIMPosition();
Expand Down Expand Up @@ -1279,7 +1287,7 @@ class AUTOEXEC:public Module_base {
}
//#endif /* (WIN32) && (USE_TTF) */
#endif // 0
if (addexit) autoexec[i++].Install("exit");
if (addexit) autoexec[i++].Install("exit");

assert(i <= 17); /* FIXME: autoexec[] should not be fixed size */

Expand Down

0 comments on commit 9e08fa5

Please sign in to comment.