Browse Source

Unloading project library no longer deletes all imported assets

BearishSun 10 years ago
parent
commit
a4b506c55b

+ 2 - 4
BansheeCore/Source/BsRenderAPI.cpp

@@ -21,8 +21,6 @@ using namespace std::placeholders;
 
 namespace BansheeEngine 
 {
-    static const SPtr<TextureCore> sNullTexPtr;
-
 	void RenderAPI::disableTextureUnit(CoreAccessor& accessor, GpuProgramType gptype, UINT16 texUnit)
 	{
 		accessor.queueCommand(std::bind(&RenderAPICore::disableTextureUnit, RenderAPICore::instancePtr(), gptype, texUnit));
@@ -294,10 +292,10 @@ namespace BansheeEngine
     {
 		THROW_IF_NOT_CORE_THREAD;
 
-        setTexture(gptype, texUnit, false, sNullTexPtr);
+		setTexture(gptype, texUnit, false, SPtr<TextureCore>());
     }
 
-	void RenderAPICore::addClipPlane (const Plane &p)
+	void RenderAPICore::addClipPlane(const Plane &p)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 

+ 5 - 0
BansheeEditor/Include/BsProjectLibrary.h

@@ -390,6 +390,11 @@ namespace BansheeEngine
 		 */
 		void makeEntriesAbsolute();
 
+		/**  
+		 * @brief	Deletes all library entries.
+		 */
+		void clearEntries();
+
 		static const WString LIBRARY_ENTRIES_FILENAME;
 		static const WString RESOURCE_MANIFEST_FILENAME;
 

+ 26 - 7
BansheeEditor/Source/BsProjectLibrary.cpp

@@ -57,8 +57,7 @@ namespace BansheeEngine
 
 	ProjectLibrary::~ProjectLibrary()
 	{
-		if(mRootEntry != nullptr)
-			deleteDirectoryInternal(mRootEntry);
+		clearEntries();
 	}
 
 	void ProjectLibrary::update()
@@ -1013,11 +1012,8 @@ namespace BansheeEngine
 		mProjectFolder = Path::BLANK;
 		mResourcesFolder = Path::BLANK;
 
-		if (mRootEntry != nullptr)
-		{
-			deleteDirectoryInternal(mRootEntry);
-			mRootEntry = bs_new<DirectoryEntry>(mResourcesFolder, mResourcesFolder.getWTail(), nullptr);
-		}
+		clearEntries();
+		mRootEntry = bs_new<DirectoryEntry>(mResourcesFolder, mResourcesFolder.getWTail(), nullptr);
 
 		mReimportQueue.clear();
 		mDependencies.clear();
@@ -1188,6 +1184,29 @@ namespace BansheeEngine
 		mIsLoaded = true;
 	}
 
+	void ProjectLibrary::clearEntries()
+	{
+		if (mRootEntry == nullptr)
+			return;
+
+		std::function<void(LibraryEntry*)> deleteRecursive =
+			[&](LibraryEntry* entry)
+		{
+			if (entry->type == LibraryEntryType::Directory)
+			{
+				DirectoryEntry* dirEntry = static_cast<DirectoryEntry*>(entry);
+
+				for (auto& child : dirEntry->mChildren)
+					deleteRecursive(child);
+			}
+
+			bs_delete(entry);
+		};
+
+		deleteRecursive(mRootEntry);
+		mRootEntry = nullptr;
+	}
+
 	void ProjectLibrary::doOnEntryRemoved(const LibraryEntry* entry)
 	{
 		if (!onEntryRemoved.empty())