Skip to content

Commit

Permalink
Merge pull request #5322 from BOINC/mac_fix_7_24_0_crash
Browse files Browse the repository at this point in the history
Fix Mac crash bug introduced by commit e0ffbf1
  • Loading branch information
AenBleidd authored and Charlie Fenton committed Aug 11, 2023
1 parent 5b05e18 commit be291ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
18 changes: 16 additions & 2 deletions clientgui/BOINCGUIApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,21 @@ bool CBOINCGUIApp::OnInit() {
#endif
m_pConfig->Read(wxT("DisableAutoStart"), &m_iBOINCMGRDisableAutoStart, 0L);
m_pConfig->Read(wxT("LanguageISO"), &m_strISOLanguageCode, wxT(""));
bool bUseDefaultLocaleDefault =
m_bUseDefaultLocale = false;
bool bUseDefaultLocaleDefault = false;
#ifdef __WXMAC__ // wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT) does not work on Mac
wxLocale *defaultLocale = new wxLocale;
defaultLocale->Init(wxLANGUAGE_DEFAULT);
wxString defaultLanguageCode = defaultLocale->GetCanonicalName();
bUseDefaultLocaleDefault = m_strISOLanguageCode == defaultLanguageCode;
delete defaultLocale;
#else
const wxLanguageInfo *defaultLanguageInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT);
if (defaultLanguageInfo != NULL) {
// Migration: assume a selected language code that matches the system default means "auto select"
m_strISOLanguageCode == wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT)->CanonicalName;
bUseDefaultLocaleDefault = m_strISOLanguageCode == defaultLanguageInfo->CanonicalName;;
}
#endif
m_pConfig->Read(wxT("UseDefaultLocale"), &m_bUseDefaultLocale, bUseDefaultLocaleDefault);
m_pConfig->Read(wxT("GUISelection"), &m_iGUISelected, BOINC_SIMPLEGUI);
m_pConfig->Read(wxT("EventLogOpen"), &bOpenEventLog);
Expand Down Expand Up @@ -947,6 +959,7 @@ void CBOINCGUIApp::InitSupportedLanguages() {
GUI_SUPPORTED_LANG newItem;

// CDlgOptions depends on "Auto" being the first item in the list
// if
newItem.Language = wxLANGUAGE_DEFAULT;
wxString strAutoEnglish = wxT("(Automatic Detection)");
wxString strAutoTranslated = wxGetTranslation(strAutoEnglish);
Expand All @@ -968,6 +981,7 @@ void CBOINCGUIApp::InitSupportedLanguages() {
// Add known locales to the list
for (int langID = wxLANGUAGE_UNKNOWN+1; langID < wxLANGUAGE_USER_DEFINED; ++langID) {
const wxLanguageInfo* pLI = wxLocale::GetLanguageInfo(langID);
if (pLI == NULL) continue;
wxString lang_region = pLI->CanonicalName.BeforeFirst('@');
wxString lang = lang_region.BeforeFirst('_');
wxString script = pLI->CanonicalName.AfterFirst('@');
Expand Down
8 changes: 4 additions & 4 deletions clientgui/DlgEventLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ void CDlgEventLog::FindErrorMessages(bool isFiltered) {
MESSAGE* message;
wxInt32 i = 0;
if (isFiltered) {
for (i; i < m_iFilteredDocCount; i++) {
for (i=0; i < m_iFilteredDocCount; i++) {
message = wxGetApp().GetDocument()->message(GetFilteredMessageIndex(i));
if (message) {
if (message->priority == MSG_USER_ALERT) {
Expand All @@ -1096,7 +1096,7 @@ void CDlgEventLog::FindErrorMessages(bool isFiltered) {
}
}
else {
for (i; i < m_iTotalDocCount; i++) {
for (i=0; i < m_iTotalDocCount; i++) {
message = wxGetApp().GetDocument()->message(i);
if (message) {
if (message->priority == MSG_USER_ALERT) {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ void CDlgEventLog::FindProjectMessages(bool isFiltered) {
MESSAGE* message;
wxInt32 i = 0;
if (isFiltered) {
for (i; i < m_iFilteredDocCount; i++) {
for (i=0; i < m_iFilteredDocCount; i++) {
message = wxGetApp().GetDocument()->message(GetFilteredMessageIndex(i));
if (message) {
if (message->project.empty() || message->project == s_strFilteredProjectName) {
Expand All @@ -1140,7 +1140,7 @@ void CDlgEventLog::FindProjectMessages(bool isFiltered) {
}
}
else {
for (i; i < m_iTotalDocCount; i++) {
for (i=0; i < m_iTotalDocCount; i++) {
message = wxGetApp().GetDocument()->message(i);
if (message) {
if (message->project.empty() || message->project == s_strFilteredProjectName) {
Expand Down
13 changes: 8 additions & 5 deletions clientgui/DlgOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,11 @@ bool CDlgOptions::ReadSettings() {
wxString strBuffer = wxEmptyString;
wxArrayString astrDialupConnections;


wxASSERT(pDoc);
wxASSERT(pFrame);
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));


// General Tab
if (wxGetApp().UseDefaultLocale()) {
// CBOINCGUIApp::InitSupportedLanguages() ensures "Auto" is the first item in the list
Expand Down Expand Up @@ -734,7 +732,7 @@ bool CDlgOptions::SaveSettings() {
CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
long lBuffer = 0;
wxString strBuffer = wxEmptyString;

const wxLanguageInfo *newLanguageInfo = NULL;

wxASSERT(pDoc);
wxASSERT(pFrame);
Expand All @@ -750,14 +748,19 @@ bool CDlgOptions::SaveSettings() {
int selLangIdx = m_LanguageSelectionCtrl->GetSelection();
if (selLangIdx == 0) {
// CBOINCGUIApp::InitSupportedLanguages() ensures "Auto" is the first item in the list
newLangCode = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT)->CanonicalName;
newLanguageInfo = wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT);
// wxLocale::GetLanguageInfo(wxLANGUAGE_DEFAULT) may return NULL on Macintosh
newLangCode = wxEmptyString;
} else if (selLangIdx > 0) {
const std::vector<GUI_SUPPORTED_LANG>& langs = wxGetApp().GetSupportedLanguages();
if (selLangIdx < langs.size()) {
const GUI_SUPPORTED_LANG& selLang = langs[selLangIdx];
newLangCode = wxLocale::GetLanguageInfo(selLang.Language)->CanonicalName;
newLanguageInfo = wxLocale::GetLanguageInfo(selLang.Language);
}
}
if (newLanguageInfo) {
newLangCode = newLanguageInfo->CanonicalName;
}
if (newLangCode != oldLangCode) {
wxString strDialogTitle;
wxString strDialogMessage;
Expand Down

0 comments on commit be291ea

Please sign in to comment.