From fa13bf8bee8b92ae80b0ce46d623d31e5a26d24b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 24 Jun 2025 17:16:47 +0200 Subject: [PATCH] Don't crash on start up if macOS system font encoding is unknown If the encoding is not recognized (which is the case at least for the encoding used for Persian/Farsi), wxLocale::GetSystemEncoding() returns wxFONTENCODING_DEFAULT and wxFont::SetDefaultEncoding() must not be called in this case, as it asserts and, due to a separate bug, crashes as the GUI is not fully initialized yet when wxApp::Initialize() is executing. See #25561. (cherry picked from commit 5de590ffaf9ca1ebe8a619986f0217f3a44af8e5) --- docs/changes.txt | 1 + src/osx/carbon/app.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 268da62bc7..65f2e34b99 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -272,6 +272,7 @@ wxMSW wxOSX: +- Fix crash on startup when using Farsi as system language (#25561). - Do not activate "Close" button on Cmd-C (nobugshere, #25346). diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index c5c7596a46..e5ce0db58b 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -306,7 +306,12 @@ bool wxApp::Initialize(int& argc, wxChar **argv) return false; #if wxUSE_INTL - wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); + // Check if we recognize the system encoding. Note that we must not call + // SetDefaultEncoding() if we don't, as indicated by wxFONTENCODING_DEFAULT + // being returned, as SetDefaultEncoding() would assert in this case. + const wxFontEncoding defaultEncoding = wxLocale::GetSystemEncoding(); + if ( defaultEncoding != wxFONTENCODING_DEFAULT ) + wxFont::SetDefaultEncoding(defaultEncoding); #endif // these might be the startup dirs, set them to the 'usual' dir containing the app bundle