Browse Source

Bugfix: Clear resources before unloading the scripting system in order to ensure any scripting components in Prefabs are destroyed before the library is unloaded

BearishSun 8 years ago
parent
commit
2231fc8f96

+ 15 - 10
Source/BansheeCore/Resources/BsResources.cpp

@@ -27,16 +27,7 @@ namespace bs
 
 	Resources::~Resources()
 	{
-		// Unload and invalidate all resources
-		UnorderedMap<UUID, LoadedResourceData> loadedResourcesCopy;
-		
-		{
-			Lock lock(mLoadedResourceMutex);
-			loadedResourcesCopy = mLoadedResources;
-		}
-
-		for (auto& loadedResourcePair : loadedResourcesCopy)
-			destroy(loadedResourcePair.second.resource);
+		unloadAll();
 	}
 
 	HResource Resources::load(const Path& filePath, ResourceLoadFlags loadFlags)
@@ -480,6 +471,20 @@ namespace bs
 		}
 	}
 
+	void Resources::unloadAll()
+	{
+		// Unload and invalidate all resources
+		UnorderedMap<UUID, LoadedResourceData> loadedResourcesCopy;
+		
+		{
+			Lock lock(mLoadedResourceMutex);
+			loadedResourcesCopy = mLoadedResources;
+		}
+
+		for (auto& loadedResourcePair : loadedResourcesCopy)
+			destroy(loadedResourcePair.second.resource);
+	}
+
 	void Resources::destroy(ResourceHandleBase& resource)
 	{
 		if (resource.mData == nullptr)

+ 3 - 0
Source/BansheeCore/Resources/BsResources.h

@@ -162,6 +162,9 @@ namespace bs
 		 */
 		void unloadAllUnused();
 
+		/** Forces unload of all resources, whether they are being used or not. */
+		void unloadAll();
+
 		/**
 		 * Saves the resource at the specified location.
 		 *

+ 4 - 0
Source/BansheeEngine/BsApplication.cpp

@@ -21,6 +21,7 @@
 #include "Debug/BsDebugDraw.h"
 #include "Platform/BsPlatform.h"
 #include "Resources/BsEngineShaderIncludeHandler.h"
+#include "Resources/BsResources.h"
 #include "BsEngineConfig.h"
 
 namespace bs
@@ -81,6 +82,9 @@ namespace bs
 		// could have allocated parts or all of those objects.
 		SceneManager::instance().clearScene(true);
 
+		// Resources too (Prefabs especially, since they hold the same data as a scene)
+		Resources::instance().unloadAll();
+
 		// Shut down before script manager as scripts could have registered shortcut callbacks
 		ShortcutManager::shutDown();