Browse Source

Fixing an issue where unloading a resource could cause a race condition

Marko Pintera 13 years ago
parent
commit
6fd41c675b

+ 5 - 0
CamelotClient/CamelotClient.cpp

@@ -231,6 +231,11 @@ int CALLBACK WinMain(
 	gResources().unload(fragProgRef);
 	gResources().unload(fragProgRef);
 	gResources().unload(vertProgRef);
 	gResources().unload(vertProgRef);
 
 
+	testTexRef.reset();
+	dbgMeshRef.reset();
+	fragProgRef.reset();
+	vertProgRef.reset();
+
 	testModelGO->destroy();
 	testModelGO->destroy();
 	testModelGO = nullptr;
 	testModelGO = nullptr;
 	testRenderable = nullptr;
 	testRenderable = nullptr;

+ 0 - 11
CamelotRenderer/Include/CmResourceHandle.h

@@ -139,17 +139,6 @@ namespace CamelotEngine
 			mData = std::shared_ptr<ResourceHandleData>(new ResourceHandleData());
 			mData = std::shared_ptr<ResourceHandleData>(new ResourceHandleData());
 		}
 		}
 
 
-		/**
-		 * @brief	Clears the data this handle (and all copies of it) points to
-		 * 			
-		 * @note	Should only be called by internal methods
-		 */
-		void _invalidate()
-		{
-			mData->mPtr = nullptr;
-			mData->mIsCreated = false;
-		}
-
 		template<class _Ty>
 		template<class _Ty>
 		struct CM_Bool_struct
 		struct CM_Bool_struct
 		{
 		{

+ 1 - 2
CamelotRenderer/Source/CmResources.cpp

@@ -225,10 +225,9 @@ namespace CamelotEngine
 	void Resources::unload(BaseResourceHandle resource)
 	void Resources::unload(BaseResourceHandle resource)
 	{
 	{
 		if(!resource.isLoaded()) // If it's still loading wait until that finishes
 		if(!resource.isLoaded()) // If it's still loading wait until that finishes
-			resource.waitUntilLoaded(); // TODO - What if resource isn't being loaded at all, or has already been unloaded?
+			resource.waitUntilLoaded();
 
 
 		resource->destroy();
 		resource->destroy();
-		resource._invalidate();
 
 
 		mLoadedResources.erase(resource.getUUID());
 		mLoadedResources.erase(resource.getUUID());
 	}
 	}