summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-05-14 21:04:49 +0000
committerfrosch <frosch@openttd.org>2012-05-14 21:04:49 +0000
commitc6ed8c01b3d729b546af8de5b37cac1814074a0c (patch)
treea10a8954331585441161553efca25e639aa23317
parent1ba36d07cf16c8501883f205e1ffb6a094a604c7 (diff)
downloadopenttd-c6ed8c01b3d729b546af8de5b37cac1814074a0c.tar.xz
(svn r24250) -Fix [FS#5154]: Do not immediately display error messages from parsing the cfg file, but schedule them for displaying after the GUI is prepared for it.
-rw-r--r--src/error.h3
-rw-r--r--src/error_gui.cpp31
-rw-r--r--src/settings.cpp50
3 files changed, 67 insertions, 17 deletions
diff --git a/src/error.h b/src/error.h
index ec083f1c6..eeb90557d 100644
--- a/src/error.h
+++ b/src/error.h
@@ -42,6 +42,9 @@ public:
~ErrorMessageData();
ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, uint textref_stack_size = 0, const uint32 *textref_stack = NULL);
+ void SetDParam(uint n, uint64 v);
+ void SetDParamStr(uint n, const char *str);
+
void CopyOutDParams();
};
diff --git a/src/error_gui.cpp b/src/error_gui.cpp
index b6f1d02a2..b054f8834 100644
--- a/src/error_gui.cpp
+++ b/src/error_gui.cpp
@@ -136,6 +136,27 @@ void ErrorMessageData::CopyOutDParams()
}
}
+/**
+ * Set a error string parameter.
+ * @param n Parameter index
+ * @param v Parameter value
+ */
+void ErrorMessageData::SetDParam(uint n, uint64 v)
+{
+ this->decode_params[n] = v;
+}
+
+/**
+ * Set a rawstring parameter.
+ * @param n Parameter index
+ * @param str Raw string
+ */
+void ErrorMessageData::SetDParamStr(uint n, const char *str)
+{
+ free(this->strings[n]);
+ this->strings[n] = strdup(str);
+}
+
/** Define a queue with errors. */
typedef std::list<ErrorMessageData> ErrorList;
/** The actual queue with errors. */
@@ -386,3 +407,13 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
new ErrmsgWindow(data);
}
}
+
+/**
+ * Schedule a list of errors.
+ * Note: This does not try to display the error now. This is useful if the window system is not yet running.
+ * @param data Error message datas; cleared afterwards
+ */
+void ScheduleErrorMessage(ErrorList &datas)
+{
+ _error_list.splice(_error_list.end(), datas);
+}
diff --git a/src/settings.cpp b/src/settings.cpp
index 74fb4b3ec..718369492 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -77,6 +77,10 @@ GameSettings _settings_newgame; ///< Game settings for new games (updated from
VehicleDefaultSettings _old_vds; ///< Used for loading default vehicles settings from old savegames
char *_config_file; ///< Configuration file of OpenTTD
+typedef std::list<ErrorMessageData> ErrorList;
+static ErrorList _settings_error_list; ///< Errors while loading minimal settings.
+
+
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list);
@@ -348,14 +352,16 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
char *end;
size_t val = strtoul(str, &end, 0);
if (end == str) {
- SetDParamStr(0, str);
- SetDParamStr(1, desc->name);
- ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
+ ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
+ msg.SetDParamStr(0, str);
+ msg.SetDParamStr(1, desc->name);
+ _settings_error_list.push_back(msg);
return desc->def;
}
if (*end != '\0') {
- SetDParamStr(0, desc->name);
- ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS, WL_CRITICAL);
+ ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS);
+ msg.SetDParamStr(0, desc->name);
+ _settings_error_list.push_back(msg);
}
return (void*)val;
}
@@ -367,29 +373,33 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
if (r != (size_t)-1) return (void*)r; // and here goes converted value
- SetDParamStr(0, str);
- SetDParamStr(1, desc->name);
- ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
+ ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
+ msg.SetDParamStr(0, str);
+ msg.SetDParamStr(1, desc->name);
+ _settings_error_list.push_back(msg);
return desc->def;
}
case SDT_MANYOFMANY: {
size_t r = LookupManyOfMany(desc->many, str);
if (r != (size_t)-1) return (void*)r;
- SetDParamStr(0, str);
- SetDParamStr(1, desc->name);
- ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
+ ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
+ msg.SetDParamStr(0, str);
+ msg.SetDParamStr(1, desc->name);
+ _settings_error_list.push_back(msg);
return desc->def;
}
- case SDT_BOOLX:
+ case SDT_BOOLX: {
if (strcmp(str, "true") == 0 || strcmp(str, "on") == 0 || strcmp(str, "1") == 0) return (void*)true;
if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
- SetDParamStr(0, str);
- SetDParamStr(1, desc->name);
- ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
+ ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
+ msg.SetDParamStr(0, str);
+ msg.SetDParamStr(1, desc->name);
+ _settings_error_list.push_back(msg);
return desc->def;
+ }
case SDT_STRING: return orig_str;
case SDT_INTLIST: return str;
@@ -531,8 +541,9 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
case SDT_INTLIST: {
if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
- SetDParamStr(0, sdb->name);
- ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
+ ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
+ msg.SetDParamStr(0, sdb->name);
+ _settings_error_list.push_back(msg);
/* Use default */
LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
@@ -1648,6 +1659,11 @@ void LoadFromConfig(bool minimal)
HandleOldDiffCustom(false);
ValidateSettings();
+
+ /* Display sheduled errors */
+ extern void ScheduleErrorMessage(ErrorList &datas);
+ ScheduleErrorMessage(_settings_error_list);
+ if (FindWindowById(WC_ERRMSG, 0) == NULL) ShowFirstError();
}
delete ini;