Skip to content

Commit e003e02

Browse files
author
Danny Glover
committed
Linux: Fix crash due to unknown locale.
- Fixed a crash that would occur if wxWidgets couldn't determine the users locale.
1 parent 1db205f commit e003e02

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

platform/linux/Rtt_LinuxContext.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,15 @@ namespace Rtt
272272
// read build.settings
273273
if (fProjectSettings->HasBuildSettings())
274274
{
275-
wxString localeName = wxLocale::GetLanguageInfo(wxLocale::GetSystemLanguage())->CanonicalName.Lower();
275+
int systemLanguage = wxLocale::GetSystemLanguage();
276+
277+
// fallback to en_us if wx wasn't able to determine the system language
278+
if (systemLanguage == wxLANGUAGE_UNKNOWN)
279+
{
280+
systemLanguage = wxLANGUAGE_ENGLISH_US;
281+
}
282+
283+
wxString localeName = wxLocale::GetLanguageInfo(systemLanguage)->CanonicalName.Lower();
276284
string langCode = localeName.ToStdString().substr(0, 2);
277285
string countryCode = localeName.ToStdString().substr(3, 5);
278286
int minWidth = fProjectSettings->GetMinWindowViewWidth();

platform/linux/Rtt_LinuxPlatform.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,15 @@ namespace Rtt
574574

575575
// Fetch the requested preference value.
576576
const char *resultPointer = "";
577-
wxString localeName = wxLocale::GetLanguageInfo(wxLocale::GetSystemLanguage())->CanonicalName.Lower();
577+
int systemLanguage = wxLocale::GetSystemLanguage();
578+
579+
// fallback to en_us if wx wasn't able to determine the system language
580+
if (systemLanguage == wxLANGUAGE_UNKNOWN)
581+
{
582+
systemLanguage = wxLANGUAGE_ENGLISH_US;
583+
}
584+
585+
wxString localeName = wxLocale::GetLanguageInfo(systemLanguage)->CanonicalName.Lower();
578586

579587
switch (category)
580588
{

platform/linux/linux_rtt.project

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,6 @@
14971497
<Preprocessor Value="wxUSE_UNSAFE_WXSTRING_CONV"/>
14981498
<Preprocessor Value="wxUSE_STD_CONTAINERS_COMPATIBLY"/>
14991499
<Preprocessor Value="wxUSE_GLCANVAS"/>
1500-
<Preprocessor Value="_DEBUG"/>
15011500
<Preprocessor Value="Rtt_LINUX_ENV"/>
15021501
<Preprocessor Value="FT2_BUILD_LIBRARY"/>
15031502
<Preprocessor Value="ALMIXER_COMPILE_WITHOUT_SDL"/>

0 commit comments

Comments
 (0)