Skip to content
This repository has been archived by the owner on Jun 16, 2019. It is now read-only.

Commit

Permalink
Fix race condition crash: cannot open prefs when no game is selected.
Browse files Browse the repository at this point in the history
When encountering a fatal error, before completely bailing out, the user is asked if he wants to have a last change editing the preferences. The prefs dialog requires a valid game configuration present. Here's the race condition: no game configuration, no installable packs -> fatal errror -> user asked to edit prefs. But: no game configuration, not able to edit prefs.

Implemented solution: simply don't ask the user to edit prefs if it's technically not possible (at least better then a crash).
  • Loading branch information
mfn committed Dec 27, 2009
1 parent b729ef1 commit e11933c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
24 changes: 16 additions & 8 deletions radiant/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,24 @@ void Error (const char *error, ...)
}
}

strcat (text, "An unrecoverable error has occured.\n"
"Would you like to edit Preferences before exiting Radiant?");
strcat (text, "An unrecoverable error has occured.\n");

Sys_Printf(text);
if (!g_PrefsDlg.isInitialized()) {

if (gtk_MessageBox(NULL, text, "Error", MB_YESNO) == IDYES)
{
Sys_Printf("Doing prefs..\n");
g_PrefsDlg.LoadPrefs ();
g_PrefsDlg.DoModal();
gtk_MessageBox(NULL, text, "Error", MB_OK);

} else {

strcat(text, "Would you like to edit Preferences before exiting Radiant?");

Sys_Printf(text);

if (gtk_MessageBox(NULL, text, "Error", MB_YESNO) == IDYES)
{
Sys_Printf("Doing prefs..\n");
g_PrefsDlg.LoadPrefs ();
g_PrefsDlg.DoModal();
}
}

QGL_Shutdown();
Expand Down
13 changes: 12 additions & 1 deletion radiant/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ static void OnButtonClean (GtkWidget *widget, gpointer data)
// profile_load_int takes an argument to use if the value is not found
PrefsDlg::PrefsDlg ()
{
m_bIsInitialized = FALSE;
m_bWarn = TRUE;
m_nMouse = 1;
m_nView = MainFrame::eRegular;
Expand Down Expand Up @@ -1507,6 +1508,7 @@ void PrefsDlg::Init()
m_rc_path = g_string_new (g_strGameToolsPath.GetBuffer() );
m_inipath = g_string_new (m_rc_path->str);
g_string_append (m_inipath, PREFS_LOCAL_FILENAME);
m_bIsInitialized = true;
return;
}
#endif
Expand All @@ -1521,7 +1523,7 @@ void PrefsDlg::Init()
// then the ini file
m_inipath = g_string_new (m_rc_path->str);
g_string_append (m_inipath, PREFS_LOCAL_FILENAME);

m_bIsInitialized = true;
}

void PrefsDlg::UpdateData (bool retrieve)
Expand Down Expand Up @@ -2844,6 +2846,11 @@ void PrefsDlg::LoadPrefs ()
{
int i;

if (!isInitialized()) {
Sys_Printf("PrefsDlg::LoadPrefs() called without being initialized, leaving\n");
return;
}

// first things first, load prefs from global prefs
mGamesDialog.LoadPrefs();

Expand Down Expand Up @@ -3245,6 +3252,10 @@ void PrefsDlg::DoSensitivity()
}
}

bool PrefsDlg::isInitialized()
{
return m_bIsInitialized;
}
/*
============================================================
CGameInstall
Expand Down
2 changes: 2 additions & 0 deletions radiant/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,12 @@ class PrefsDlg : public Dialog
this holds global level preferences
*/
CGameDialog mGamesDialog;
bool isInitialized();
protected:
// warning about old project files
bool m_bWarn;
list<CGameDescription *> mGames;
bool m_bIsInitialized;

public:
// last light intensity used in the CLightPrompt dialog, stored in registry
Expand Down

0 comments on commit e11933c

Please sign in to comment.