changeset 18632:eb93faa96b65 draft

(svn r23479) -Codechange: keep a copy of raw strings from the parameters of the error messages
author rubidium <rubidium@openttd.org>
date Sat, 10 Dec 2011 16:04:32 +0000
parents 6e3c0492d7b0
children b99ace5e6811
files src/error_gui.cpp
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/error_gui.cpp
+++ b/src/error_gui.cpp
@@ -76,6 +76,7 @@
 protected:
 	uint duration;                  ///< Length of display of the message. 0 means forever,
 	uint64 decode_params[20];       ///< Parameters of the message strings.
+	const char *strings[20];        ///< Copies of raw strings that were used.
 	uint textref_stack_size;        ///< Number of uint32 values to put on the #TextRefStack for the error message.
 	uint32 textref_stack[16];       ///< Values to put on the #TextRefStack for the error message.
 	StringID summary_msg;           ///< General error message showed in first line. Must be valid.
@@ -91,6 +92,18 @@
 	ErrorMessageData(const ErrorMessageData &data)
 	{
 		*this = data;
+		for (size_t i = 0; i < lengthof(this->strings); i++) {
+			if (this->strings[i] != NULL) {
+				this->strings[i] = strdup(this->strings[i]);
+				this->decode_params[i] = (size_t)this->strings[i];
+			}
+		}
+	}
+
+	/** Free all the strings. */
+	~ErrorMessageData()
+	{
+		for (size_t i = 0; i < lengthof(this->strings); i++) free(this->strings[i]);
 	}
 
 	/**
@@ -111,7 +124,7 @@
 	{
 		this->position.x = x;
 		this->position.y = y;
-		CopyOutDParam(this->decode_params, 0, lengthof(this->decode_params));
+		CopyOutDParam(this->decode_params, this->strings, detailed_msg == INVALID_STRING_ID ? summary_msg : detailed_msg, lengthof(this->decode_params));
 		if (textref_stack_size > 0) {
 			MemCpyT(this->textref_stack, textref_stack, textref_stack_size);
 		}
@@ -312,6 +325,7 @@
 	if (w != NULL) {
 		if (w->IsCritical()) _errors.push_front(*w);
 		_window_system_initialized = false;
+		delete w;
 	}
 }