Skip to content

Commit

Permalink
Merge pull request #4462 from maron2000/update_sdl2_28_2
Browse files Browse the repository at this point in the history
Fix macos crash on launch when output=surface or auto (SDL2)
  • Loading branch information
joncampbell123 committed Sep 15, 2023
2 parents 7d70427 + bbefcec commit f4d69fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ extern int tryconvertcp, Reflect_Menu(void);
#include <output/output_tools.h>
#include <output/output_ttf.h>
#include <output/output_tools_xbrz.h>
static bool init_output = false;

#if defined(WIN32)
#include "resource.h"
Expand Down Expand Up @@ -3714,7 +3715,13 @@ static void GUI_StartUp() {
sdl.desktop.isperfect = false; /* Reset before selection */
if (output == "surface")
{
#if C_DIRECT3D
if(!init_output) OUTPUT_DIRECT3D_Select();
#elif C_OPENGL
if(!init_output) OUTPUT_OPENGL_Select(GLBilinear); // Initialize screen before switching to TTF (required for macOS builds)
#endif
OUTPUT_SURFACE_Select();
init_output = true;
#if C_OPENGL
}
else if (output == "opengl" || output == "openglhq")
Expand Down Expand Up @@ -3749,18 +3756,21 @@ static void GUI_StartUp() {
else if (output == "ttf")
{
LOG_MSG("SDL(sdlmain.cpp): TTF activated");
#if C_OPENGL
OUTPUT_OPENGL_Select(GLBilinear); // Initialize screen before switching to TTF (required for macOS builds)
#else
OUTPUT_SURFACE_Select();
#endif // C_OPENGL
#if ((WIN32 && !defined(C_SDL2)) || MACOSX) && C_OPENGL
if(!init_output) OUTPUT_OPENGL_Select(GLBilinear); // Initialize screen before switching to TTF (required for Windows & macOS builds)
#endif
OUTPUT_TTF_Select(0);
init_output = true;
}
#endif
else
{
LOG_MSG("SDL: Unsupported output device %s, switching back to surface",output.c_str());
#if MACOSX && C_OPENGL
if(!init_output) OUTPUT_OPENGL_Select(GLBilinear); // Initialize screen before switching to surface (required for macOS builds)
#endif
OUTPUT_SURFACE_Select(); // should not reach there anymore
init_output = true;
}

sdl.overscan_width=(unsigned int)section->Get_int("overscan");
Expand Down
5 changes: 4 additions & 1 deletion src/output/output_ttf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,10 @@ void ttf_switch_on(bool ss=true) {
#endif
}
bool OpenGL_using(void), gl = OpenGL_using();
change_output(10);
#if defined(WIN32) && !defined(C_SDL2)
change_output(3); // call OUTPUT_OPENGL_Select(GLBilinear) to initialize output before enabling TTF output on Windows builds (does nothing if OpenGL not available)
#endif
change_output(10); // call OUTPUT_TTF_Select()
SetVal("sdl", "output", "ttf");
std::string showdbcsstr = static_cast<Section_prop *>(control->GetSection("dosv"))->Get_string("showdbcsnodosv");
showdbcs = showdbcsstr=="true"||showdbcsstr=="1"||(showdbcsstr=="auto" && (loadlang || dbcs_sbcs));
Expand Down

0 comments on commit f4d69fb

Please sign in to comment.