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 5de590ffaf)
This commit is contained in:
Vadim Zeitlin
2025-06-24 17:22:15 +02:00
parent 8bd21d511f
commit fa13bf8bee
2 changed files with 7 additions and 1 deletions
+1
View File
@@ -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).
+6 -1
View File
@@ -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