(svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
authorbelugas
Sat, 17 May 2008 03:29:16 +0000
changeset 9267 22095cc802dd
parent 9266 9502b91d38ee
child 9268 fa447d3b408d
(svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
This will allow to free the said window only once, and not twice otherwise
src/window.cpp
src/window_gui.h
--- a/src/window.cpp	Sat May 17 03:16:04 2008 +0000
+++ b/src/window.cpp	Sat May 17 03:29:16 2008 +0000
@@ -2350,3 +2350,13 @@
 		w->top = top;
 	}
 }
+
+/** Destructor of the base class PickerWindowBase
+ * Main utility is to stop the base Window destructor from triggering
+ * a free while the child will already be free, in this case by the ResetObjectToPlace().
+ */
+PickerWindowBase::~PickerWindowBase()
+{
+	this->window_class = WC_INVALID; // stop the ancestor from freeing the already (to be) child
+	ResetObjectToPlace();
+}
--- a/src/window_gui.h	Sat May 17 03:16:04 2008 +0000
+++ b/src/window_gui.h	Sat May 17 03:29:16 2008 +0000
@@ -256,7 +256,7 @@
 	int32 dest_scrollpos_y;
 };
 
-	/**
+/**
  * Data structure for an opened window
  */
 struct Window : ZeroedMemoryAllocator {
@@ -493,6 +493,17 @@
 	/*** End of the event handling ***/
 };
 
+/**
+ * Data structure for a window opened from a toolbar
+ */
+class PickerWindowBase : public Window {
+
+public:
+	PickerWindowBase(const WindowDesc *desc) : Window(desc) {}; // nothing special yet, just propagation
+
+	virtual ~PickerWindowBase();
+};
+
 enum SortListFlags {
 	VL_NONE    = 0,      ///< no sort
 	VL_DESC    = 1 << 0, ///< sort descending or ascending