Browse Source

Bugfix: Crash when clear the scene tree view and a non-top-level object was selected

BearishSun 7 years ago
parent
commit
8c73f249ff

+ 10 - 0
Source/EditorCore/GUI/BsGUIResourceTreeView.cpp

@@ -54,6 +54,11 @@ namespace bs
 	{
 	{
 		clearDropTarget();
 		clearDropTarget();
 
 
+		for(auto& child : mRootElement.mChildren)
+			deleteTreeElement((ResourceTreeElement*)&child);
+
+		mRootElement.mChildren.clear();
+
 		ResourceTreeViewLocator::_provide(nullptr);
 		ResourceTreeViewLocator::_provide(nullptr);
 	}
 	}
 
 
@@ -164,6 +169,11 @@ namespace bs
 	{
 	{
 		closeTemporarilyExpandedElements(); // In case this element is one of them
 		closeTemporarilyExpandedElements(); // In case this element is one of them
 
 
+		for(auto& child : element->mChildren)
+			deleteTreeElement((ResourceTreeElement*)child);
+
+		element->mChildren.clear();
+
 		if (element->mIsHighlighted)
 		if (element->mIsHighlighted)
 			clearPing();
 			clearPing();
 
 

+ 10 - 0
Source/EditorCore/GUI/BsGUISceneTreeView.cpp

@@ -54,6 +54,11 @@ namespace bs
 
 
 	GUISceneTreeView::~GUISceneTreeView()
 	GUISceneTreeView::~GUISceneTreeView()
 	{
 	{
+		for(auto& child : mRootElement.mChildren)
+			deleteTreeElementInternal(child);
+
+		mRootElement.mChildren.clear();
+
 		SceneTreeViewLocator::_remove(this);
 		SceneTreeViewLocator::_remove(this);
 	}
 	}
 
 
@@ -286,6 +291,11 @@ namespace bs
 	{
 	{
 		closeTemporarilyExpandedElements(); // In case this element is one of them
 		closeTemporarilyExpandedElements(); // In case this element is one of them
 
 
+		for(auto& child : element->mChildren)
+			deleteTreeElementInternal(child);
+
+		element->mChildren.clear();
+
 		if (element->mIsHighlighted)
 		if (element->mIsHighlighted)
 			clearPing();
 			clearPing();
 
 

+ 2 - 2
Source/EditorCore/GUI/BsGUISceneTreeView.h

@@ -124,8 +124,6 @@ namespace bs
 		virtual ~GUISceneTreeView();
 		virtual ~GUISceneTreeView();
 
 
 	protected:
 	protected:
-		SceneTreeElement mRootElement;
-
 		GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle, 
 		GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle, 
 			const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle, 
 			const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle, 
 			const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
 			const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions);
@@ -190,6 +188,8 @@ namespace bs
 		 */
 		 */
 		static void cleanDuplicates(Vector<HSceneObject>& objects);
 		static void cleanDuplicates(Vector<HSceneObject>& objects);
 
 
+		SceneTreeElement mRootElement;
+
 		Vector<HSceneObject> mCopyList;
 		Vector<HSceneObject> mCopyList;
 		bool mCutFlag;
 		bool mCutFlag;
 
 

+ 1 - 4
Source/EditorCore/GUI/BsGUITreeView.cpp

@@ -38,16 +38,13 @@ namespace bs
 
 
 	GUITreeView::TreeElement::~TreeElement()
 	GUITreeView::TreeElement::~TreeElement()
 	{
 	{
-		for(auto& child : mChildren)
-			bs_delete(child);
+		assert(mChildren.empty());
 
 
 		if(mFoldoutBtn != nullptr)
 		if(mFoldoutBtn != nullptr)
 			GUIElement::destroy(mFoldoutBtn);
 			GUIElement::destroy(mFoldoutBtn);
 
 
 		if(mElement != nullptr)
 		if(mElement != nullptr)
 			GUIElement::destroy(mElement);
 			GUIElement::destroy(mElement);
-
-		mChildren.clear();
 	}
 	}
 
 
 	bool GUITreeView::TreeElement::isParentRec(TreeElement* element) const
 	bool GUITreeView::TreeElement::isParentRec(TreeElement* element) const