Просмотр исходного кода

Don't report destroyed scene objects from Selection. Fixes crash due to assembly refresh.

BearishSun 9 лет назад
Родитель
Сommit
c62c09ec13
2 измененных файлов с 35 добавлено и 1 удалено
  1. 6 1
      Source/BansheeEditor/Include/BsSelection.h
  2. 29 0
      Source/BansheeEditor/Source/BsSelection.cpp

+ 6 - 1
Source/BansheeEditor/Include/BsSelection.h

@@ -82,11 +82,16 @@ namespace BansheeEngine
 		/**	Updates scene and resource tree views with new selection. */
 		/**	Updates scene and resource tree views with new selection. */
 		void updateTreeViews();
 		void updateTreeViews();
 
 
-		Vector<HSceneObject> mSelectedSceneObjects;
+		/** Removes any destroyed scene objects from the selected scene object list. */
+		void pruneDestroyedSceneObjects() const;
+
+		mutable Vector<HSceneObject> mSelectedSceneObjects;
 		Vector<Path> mSelectedResourcePaths;
 		Vector<Path> mSelectedResourcePaths;
 
 
 		HMessage mSceneSelectionChangedConn;
 		HMessage mSceneSelectionChangedConn;
 		HMessage mResourceSelectionChangedConn;
 		HMessage mResourceSelectionChangedConn;
+
+		mutable Vector<HSceneObject> mTempSO;
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 29 - 0
Source/BansheeEditor/Source/BsSelection.cpp

@@ -26,6 +26,7 @@ namespace BansheeEngine
 
 
 	const Vector<HSceneObject>& Selection::getSceneObjects() const
 	const Vector<HSceneObject>& Selection::getSceneObjects() const
 	{
 	{
+		pruneDestroyedSceneObjects();
 		return mSelectedSceneObjects;
 		return mSelectedSceneObjects;
 	}
 	}
 
 
@@ -36,6 +37,7 @@ namespace BansheeEngine
 
 
 		updateTreeViews();
 		updateTreeViews();
 
 
+		pruneDestroyedSceneObjects();
 		onSelectionChanged(mSelectedSceneObjects, Vector<Path>());
 		onSelectionChanged(mSelectedSceneObjects, Vector<Path>());
 	}
 	}
 
 
@@ -135,6 +137,7 @@ namespace BansheeEngine
 			mSelectedSceneObjects = newSelection;
 			mSelectedSceneObjects = newSelection;
 			mSelectedResourcePaths.clear();
 			mSelectedResourcePaths.clear();
 
 
+			pruneDestroyedSceneObjects();
 			onSelectionChanged(mSelectedSceneObjects, Vector<Path>());
 			onSelectionChanged(mSelectedSceneObjects, Vector<Path>());
 		}
 		}
 	}
 	}
@@ -186,9 +189,35 @@ namespace BansheeEngine
 		if (sceneTreeView != nullptr)
 		if (sceneTreeView != nullptr)
 		{
 		{
 			// Copy in case setSelection modifies the original.
 			// Copy in case setSelection modifies the original.
+			pruneDestroyedSceneObjects();
 			Vector<HSceneObject> copy = mSelectedSceneObjects;
 			Vector<HSceneObject> copy = mSelectedSceneObjects;
 
 
 			sceneTreeView->setSelection(copy);
 			sceneTreeView->setSelection(copy);
 		}
 		}
 	}
 	}
+
+	void Selection::pruneDestroyedSceneObjects() const
+	{
+		bool anyDestroyed = false;
+		for (auto& SO : mSelectedSceneObjects)
+		{
+			if (!SO.isDestroyed(true))
+			{
+				anyDestroyed = true;
+				break;
+			}
+		}
+
+		if (!anyDestroyed) // Test for quick exit for the most common case
+			return;
+
+		for(auto& SO : mSelectedSceneObjects)
+		{
+			if(!SO.isDestroyed(true))
+				mTempSO.push_back(SO);
+		}
+
+		mSelectedSceneObjects.swap(mTempSO);
+		mTempSO.clear();
+	}
 }
 }