Panagiotis Christopoulos Charitos 15 年之前
父節點
當前提交
83406f6f8e

File diff suppressed because it is too large
+ 0 - 1
build/debug/Makefile


+ 23 - 5
src/Resources/Core/ResourceManager.cpp

@@ -26,13 +26,14 @@
 	} \
 	\
 	template<> \
-	void ResourceManager::unload<type__>(const Types<type__>::Hook& hook) \
+	void ResourceManager::deallocRsrc<type__>(type__* rsrc) \
 	{ \
-		unloadR<type__>(hook); \
+		delete rsrc; \
 	}
 
 
-SPECIALIZE_TEMPLATE_STUFF(Texture, textures)
+
+//SPECIALIZE_TEMPLATE_STUFF(Texture, textures)
 SPECIALIZE_TEMPLATE_STUFF(ShaderProg, shaderProgs)
 SPECIALIZE_TEMPLATE_STUFF(Material, materials)
 SPECIALIZE_TEMPLATE_STUFF(Mesh, meshes)
@@ -45,10 +46,27 @@ SPECIALIZE_TEMPLATE_STUFF(Model, models)
 SPECIALIZE_TEMPLATE_STUFF(Skin, skins)
 SPECIALIZE_TEMPLATE_STUFF(DummyRsrc, dummies)
 
-
 //======================================================================================================================
-// allocAndLoadRsrc <Texture>                                                                                          =
+// Texture Specializations                                                                                             =
 //======================================================================================================================
+
+template<>
+ResourceManager::Types<Texture>::Container& ResourceManager::choseContainer<Texture>()
+{
+	return textures;
+}
+
+
+template<>
+void ResourceManager::deallocRsrc<Texture>(Texture* rsrc)
+{
+	if(rsrc != dummyTex.get() && rsrc != dummyNormTex.get())
+	{
+		delete rsrc;
+	}
+}
+
+
 template<>
 void ResourceManager::allocAndLoadRsrc(const char* filename, Texture*& ptr)
 {

+ 7 - 1
src/Resources/Core/ResourceManager.h

@@ -97,10 +97,16 @@ class ResourceManager
 		void unloadR(const typename Types<Type>::Hook& info);
 		
 		/// Allocate and load a resource.
-		/// This method allocates memory for a resource and loads it (calls the load metod). Its been used by the load
+		/// This method allocates memory for a resource and loads it (calls the load method). Its been used by the load
 		/// method. Its a separate method because we want to specialize it for async loaded resources
 		template<typename Type>
 		void allocAndLoadRsrc(const char* filename, Type*& ptr);
+
+		/// Dealocate the resource. Its separate for two reasons:
+		/// - Because we want to specialize it for the async loaded resources
+		/// - Because we cannot have the operator delete in a template body. Apparently the compiler is to dump to decide
+		template<typename Type>
+		void deallocRsrc(Type* rsrc);
 };
 
 

+ 9 - 4
src/Resources/Core/ResourceManager.inl.h

@@ -20,10 +20,10 @@ void ResourceManager::allocAndLoadRsrc(const char* filename, Type*& newInstance)
 	{
 		//ERROR("fuckkkkkkkkkk " << e.what());
 
-		if(newInstance != NULL)
+		/*if(newInstance != NULL)
 		{
 			delete newInstance;
-		}
+		}*/
 		
 		throw EXCEPTION("Cannot load \"" + filename + "\": " + e.what());
 	}
@@ -83,7 +83,7 @@ typename ResourceManager::Types<Type>::Hook& ResourceManager::load(const char* f
 // unload                                                                                                              =
 //======================================================================================================================
 template<typename Type>
-void ResourceManager::unloadR(const typename Types<Type>::Hook& hook)
+void ResourceManager::unload(const typename Types<Type>::Hook& hook)
 {
 	// Chose container
 	typename Types<Type>::Container& c = choseContainer<Type>();
@@ -97,6 +97,11 @@ void ResourceManager::unloadR(const typename Types<Type>::Hook& hook)
 		throw EXCEPTION("Resource hook incorrect (\"" + hook.uuid + "\")");
 	}
 
+	if(it->uuid != hook.uuid)
+	{
+		INFO(it->uuid << " " << hook.uuid);
+	}
+
 	ASSERT(it->uuid == hook.uuid);
 	ASSERT(it->referenceCounter == hook.referenceCounter);
 
@@ -105,7 +110,7 @@ void ResourceManager::unloadR(const typename Types<Type>::Hook& hook)
 	// Delete the resource
 	if(it->referenceCounter == 0)
 	{
-		delete it->resource;
+		deallocRsrc(it->resource);
 		c.erase(it);
 	}
 }

Some files were not shown because too many files changed in this diff