Sfoglia il codice sorgente

Fixing an issue with layouts and spaces not getting removed from parent when destroyed

Marko Pintera 10 anni fa
parent
commit
2952bf6d1a

+ 4 - 0
BansheeEngine/Include/BsGUISpace.h

@@ -18,6 +18,8 @@ namespace BansheeEngine
 			_markAsClean();
 			_markAsClean();
 		}
 		}
 
 
+		~GUIFixedSpace();
+
 		/**
 		/**
 		 * @brief	Returns the size of the space in pixels.
 		 * @brief	Returns the size of the space in pixels.
 		 */
 		 */
@@ -95,6 +97,8 @@ namespace BansheeEngine
 			_markAsClean();
 			_markAsClean();
 		}
 		}
 
 
+		~GUIFlexibleSpace();
+
 		/**
 		/**
 		 * @copydoc	GUIElementBase::_getType
 		 * @copydoc	GUIElementBase::_getType
 		 */
 		 */

+ 4 - 1
BansheeEngine/Source/BsGUILayout.cpp

@@ -20,7 +20,10 @@ namespace BansheeEngine
 	{ }
 	{ }
 
 
 	GUILayout::~GUILayout() 
 	GUILayout::~GUILayout() 
-	{ }
+	{ 
+		if (mParentElement != nullptr)
+			mParentElement->_unregisterChildElement(this);
+	}
 
 
 	void GUILayout::addElement(GUIElementBase* element)
 	void GUILayout::addElement(GUIElementBase* element)
 	{
 	{

+ 12 - 0
BansheeEngine/Source/BsGUISpace.cpp

@@ -2,6 +2,12 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	GUIFixedSpace::~GUIFixedSpace()
+	{
+		if (mParentElement != nullptr)
+			mParentElement->_unregisterChildElement(this);
+	}
+
 	LayoutSizeRange GUIFixedSpace::_calculateLayoutSizeRange() const
 	LayoutSizeRange GUIFixedSpace::_calculateLayoutSizeRange() const
 	{ 
 	{ 
 		LayoutSizeRange range;
 		LayoutSizeRange range;
@@ -22,6 +28,12 @@ namespace BansheeEngine
 		bs_delete(space);
 		bs_delete(space);
 	}
 	}
 
 
+	GUIFlexibleSpace::~GUIFlexibleSpace()
+	{
+		if (mParentElement != nullptr)
+			mParentElement->_unregisterChildElement(this);
+	}
+
 	LayoutSizeRange GUIFlexibleSpace::_calculateLayoutSizeRange() const
 	LayoutSizeRange GUIFlexibleSpace::_calculateLayoutSizeRange() const
 	{
 	{
 		LayoutSizeRange range;
 		LayoutSizeRange range;

+ 0 - 8
BansheeEngine/Source/BsGUIWidget.cpp

@@ -48,14 +48,6 @@ namespace BansheeEngine
 			mOwnerTargetResizedConn.disconnect();
 			mOwnerTargetResizedConn.disconnect();
 		}
 		}
 
 
-		// Iterate over all elements in this way because each
-		// GUIElement::destroy call internally unregisters the element
-		// from the widget, and modifies the mElements array
-		while (mElements.size() > 0)
-		{
-			GUIElement::destroy(mElements[0]);
-		}
-
 		for (auto& area : mAreas)
 		for (auto& area : mAreas)
 		{
 		{
 			GUIArea::destroyInternal(area);
 			GUIArea::destroyInternal(area);