Browse Source

Finished porting to memory allocators

Marko Pintera 12 years ago
parent
commit
77df4b87a9

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -26,8 +26,8 @@
 #include "CmDebugCamera.h"
 #include "CmDebugCamera.h"
 #include "CmTestTextSprite.h"
 #include "CmTestTextSprite.h"
 
 
-//#define DX11
-#define DX9
+#define DX11
+//#define DX9
 //#define GL
 //#define GL
 
 
 using namespace CamelotEngine;
 using namespace CamelotEngine;

+ 5 - 0
CamelotCore/Include/CmCommandQueue.h

@@ -102,6 +102,11 @@ namespace CamelotEngine
 		 */
 		 */
 		std::queue<Command>* flush();
 		std::queue<Command>* flush();
 
 
+		/**
+		 * @brief	Cancels all currently queued commands.
+		 */
+		void cancelAll();
+
 		/**
 		/**
 		 * @brief	Plays all provided commands. Should only be called from the render thread. To get the
 		 * @brief	Plays all provided commands. Should only be called from the render thread. To get the
 		 * 			commands call flushCommands().
 		 * 			commands call flushCommands().

+ 6 - 0
CamelotCore/Source/CmCommandQueue.cpp

@@ -158,6 +158,12 @@ namespace CamelotEngine
 		playback(commands, boost::function<void(UINT32)>());
 		playback(commands, boost::function<void(UINT32)>());
 	}
 	}
 
 
+	void CommandQueue::cancelAll()
+	{
+		std::queue<CommandQueue::Command>* commands = flush();
+		CM_DELETE(commands, std::queue<Command>, PoolAlloc);
+	}
+
 	bool CommandQueue::isEmpty()
 	bool CommandQueue::isEmpty()
 	{
 	{
 		CM_LOCK_MUTEX(mCommandBufferMutex);
 		CM_LOCK_MUTEX(mCommandBufferMutex);

+ 1 - 2
CamelotCore/Source/CmDeferredRenderContext.cpp

@@ -160,7 +160,6 @@ namespace CamelotEngine
 
 
 	void DeferredRenderContext::cancelAll()
 	void DeferredRenderContext::cancelAll()
 	{
 	{
-		std::queue<CommandQueue::Command>* commands = mCommandQueue->flush();
-		delete commands;
+		mCommandQueue->cancelAll();
 	}
 	}
 }
 }

+ 6 - 3
CamelotCore/Source/CmSprite.cpp

@@ -107,14 +107,17 @@ namespace CamelotEngine
 	{
 	{
 		for(auto& renderElem : mCachedRenderElements)
 		for(auto& renderElem : mCachedRenderElements)
 		{
 		{
+			UINT32 vertexCount = renderElem.numQuads * 4;
+			UINT32 indexCount = renderElem.numQuads * 6;
+
 			if(renderElem.vertices != nullptr)
 			if(renderElem.vertices != nullptr)
-				delete[] renderElem.vertices;
+				CM_DELETE_ARRAY(renderElem.vertices, Vector2, vertexCount, ScratchAlloc);
 
 
 			if(renderElem.uvs != nullptr)
 			if(renderElem.uvs != nullptr)
-				delete[] renderElem.uvs;
+				CM_DELETE_ARRAY(renderElem.uvs, Vector2, vertexCount, ScratchAlloc);
 
 
 			if(renderElem.indexes != nullptr)
 			if(renderElem.indexes != nullptr)
-				delete[] renderElem.indexes;
+				CM_DELETE_ARRAY(renderElem.indexes, UINT32, indexCount, ScratchAlloc);
 
 
 			if(renderElem.material != nullptr)
 			if(renderElem.material != nullptr)
 			{
 			{

+ 0 - 2
CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h

@@ -3,8 +3,6 @@
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 
 
 // some D3D commonly used macros
 // some D3D commonly used macros
-#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
-#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
 #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
 #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
 
 
 // enable extended d3d debug 
 // enable extended d3d debug 

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11InputLayoutManager.cpp

@@ -166,9 +166,9 @@ namespace CamelotEngine
 		{
 		{
 			auto inputLayoutIter = mInputLayoutMap.find(iter->second);
 			auto inputLayoutIter = mInputLayoutMap.find(iter->second);
 
 
-			delete inputLayoutIter->first.bufferDeclElements;
+			CM_DELETE(inputLayoutIter->first.bufferDeclElements, list<VertexElement>::type, PoolAlloc);
 			SAFE_RELEASE(inputLayoutIter->second->inputLayout);
 			SAFE_RELEASE(inputLayoutIter->second->inputLayout);
-			delete inputLayoutIter->second;
+			CM_DELETE(inputLayoutIter->second, InputLayoutEntry, PoolAlloc);
 
 
 			mInputLayoutMap.erase(inputLayoutIter);
 			mInputLayoutMap.erase(inputLayoutIter);
 
 

+ 0 - 2
CamelotD3D9Renderer/Include/CmD3D9Prerequisites.h

@@ -41,8 +41,6 @@ THE SOFTWARE.
 #define DIRECT3D_VERSION 0x0900
 #define DIRECT3D_VERSION 0x0900
 
 
 // some D3D commonly used macros
 // some D3D commonly used macros
-#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
-#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
 #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
 #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
 
 
 // enable extended d3d debug 
 // enable extended d3d debug 

+ 0 - 2
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -290,8 +290,6 @@ namespace CamelotEngine {
         /* The current GL context  - main thread only */
         /* The current GL context  - main thread only */
         GLContext *mCurrentContext;
         GLContext *mCurrentContext;
 		typedef list<GLContext*>::type GLContextList;
 		typedef list<GLContext*>::type GLContextList;
-		/// List of background thread contexts
-		GLContextList mBackgroundContextList;
 
 
 		vector<GLuint>::type mBoundAttributes; // Only full between begin/endDraw calls
 		vector<GLuint>::type mBoundAttributes; // Only full between begin/endDraw calls
 		bool mDrawCallInProgress;
 		bool mDrawCallInProgress;

+ 0 - 12
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -179,18 +179,6 @@ namespace CamelotEngine
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
 		GLRTTManager::shutDown();
 		GLRTTManager::shutDown();
 
 
-		// Delete extra threads contexts
-		for (GLContextList::iterator i = mBackgroundContextList.begin(); 
-			i != mBackgroundContextList.end(); ++i)
-		{
-			GLContext* pCurContext = *i;
-
-			pCurContext->releaseContext();
-
-			delete pCurContext;
-		}
-		mBackgroundContextList.clear();
-
 		mBoundVertexBuffers.clear();
 		mBoundVertexBuffers.clear();
 		mBoundVertexDeclaration = nullptr;
 		mBoundVertexDeclaration = nullptr;
 		mBoundIndexBuffer = nullptr;
 		mBoundIndexBuffer = nullptr;

+ 9 - 9
CamelotUtility/Include/CmDataStream.h

@@ -375,11 +375,11 @@ namespace CamelotEngine
 	{
 	{
 	protected:
 	protected:
 		/// Reference to source stream (read)
 		/// Reference to source stream (read)
-		std::istream* mpInStream;
+		std::shared_ptr<std::istream> mpInStream;
 		/// Reference to source file stream (read-only)
 		/// Reference to source file stream (read-only)
-		std::ifstream* mpFStreamRO;
+		std::shared_ptr<std::ifstream> mpFStreamRO;
 		/// Reference to source file stream (read-write)
 		/// Reference to source file stream (read-write)
-		std::fstream* mpFStream;
+		std::shared_ptr<std::fstream> mpFStream;
         bool mFreeOnClose;	
         bool mFreeOnClose;	
 
 
 		void determineAccess();
 		void determineAccess();
@@ -389,14 +389,14 @@ namespace CamelotEngine
         @param freeOnClose Whether to delete the underlying stream on 
         @param freeOnClose Whether to delete the underlying stream on 
             destruction of this class
             destruction of this class
         */
         */
-		FileDataStream(std::ifstream* s, 
+		FileDataStream(std::shared_ptr<std::ifstream> s, 
             bool freeOnClose = true);
             bool freeOnClose = true);
 		/** Construct a read-write stream from an STL stream
 		/** Construct a read-write stream from an STL stream
 		@param s Pointer to source stream
 		@param s Pointer to source stream
 		@param freeOnClose Whether to delete the underlying stream on 
 		@param freeOnClose Whether to delete the underlying stream on 
 		destruction of this class
 		destruction of this class
 		*/
 		*/
-		FileDataStream(std::fstream* s, 
+		FileDataStream(std::shared_ptr<std::fstream> s, 
 			bool freeOnClose = true);
 			bool freeOnClose = true);
 
 
 		/** Construct named read-only stream from an STL stream
 		/** Construct named read-only stream from an STL stream
@@ -406,7 +406,7 @@ namespace CamelotEngine
             destruction of this class
             destruction of this class
         */
         */
 		FileDataStream(const String& name, 
 		FileDataStream(const String& name, 
-            std::ifstream* s, 
+            std::shared_ptr<std::ifstream> s, 
             bool freeOnClose = true);
             bool freeOnClose = true);
 
 
 		/** Construct named read-write stream from an STL stream
 		/** Construct named read-write stream from an STL stream
@@ -416,7 +416,7 @@ namespace CamelotEngine
 		destruction of this class
 		destruction of this class
 		*/
 		*/
 		FileDataStream(const String& name, 
 		FileDataStream(const String& name, 
-			std::fstream* s, 
+			std::shared_ptr<std::fstream> s, 
 			bool freeOnClose = true);
 			bool freeOnClose = true);
 
 
 		/** Construct named read-only stream from an STL stream, and tell it the size
 		/** Construct named read-only stream from an STL stream, and tell it the size
@@ -434,7 +434,7 @@ namespace CamelotEngine
 			MEMCATEGRORY_GENERAL.
 			MEMCATEGRORY_GENERAL.
         */
         */
 		FileDataStream(const String& name, 
 		FileDataStream(const String& name, 
-            std::ifstream* s, 
+            std::shared_ptr<std::ifstream> s, 
             size_t size, 
             size_t size, 
             bool freeOnClose = true);
             bool freeOnClose = true);
 
 
@@ -453,7 +453,7 @@ namespace CamelotEngine
 		MEMCATEGRORY_GENERAL.
 		MEMCATEGRORY_GENERAL.
 		*/
 		*/
 		FileDataStream(const String& name, 
 		FileDataStream(const String& name, 
-			std::fstream* s, 
+			std::shared_ptr<std::fstream> s, 
 			size_t size, 
 			size_t size, 
 			bool freeOnClose = true);
 			bool freeOnClose = true);
 
 

+ 0 - 15
CamelotUtility/Include/CmThreadDefines.h

@@ -49,7 +49,6 @@ THE SOFTWARE
 // like CM_AUTO_MUTEX but mutex held by pointer
 // like CM_AUTO_MUTEX but mutex held by pointer
 #define CM_AUTO_SHARED_MUTEX mutable boost::recursive_mutex *CM_AUTO_MUTEX_NAME;
 #define CM_AUTO_SHARED_MUTEX mutable boost::recursive_mutex *CM_AUTO_MUTEX_NAME;
 #define CM_LOCK_AUTO_SHARED_MUTEX assert(CM_AUTO_MUTEX_NAME); boost::recursive_mutex::scoped_lock cmAutoMutexLock(*CM_AUTO_MUTEX_NAME);
 #define CM_LOCK_AUTO_SHARED_MUTEX assert(CM_AUTO_MUTEX_NAME); boost::recursive_mutex::scoped_lock cmAutoMutexLock(*CM_AUTO_MUTEX_NAME);
-#define CM_DELETE_AUTO_SHARED_MUTEX assert(CM_AUTO_MUTEX_NAME); delete CM_AUTO_MUTEX_NAME;
 #define CM_COPY_AUTO_SHARED_MUTEX(from) assert(!CM_AUTO_MUTEX_NAME); CM_AUTO_MUTEX_NAME = from;
 #define CM_COPY_AUTO_SHARED_MUTEX(from) assert(!CM_AUTO_MUTEX_NAME); CM_AUTO_MUTEX_NAME = from;
 #define CM_SET_AUTO_SHARED_MUTEX_NULL CM_AUTO_MUTEX_NAME = 0;
 #define CM_SET_AUTO_SHARED_MUTEX_NULL CM_AUTO_MUTEX_NAME = 0;
 #define CM_MUTEX_CONDITIONAL(mutex) if (mutex)
 #define CM_MUTEX_CONDITIONAL(mutex) if (mutex)
@@ -63,13 +62,6 @@ THE SOFTWARE
 #define CM_RW_MUTEX(name) mutable boost::shared_mutex name
 #define CM_RW_MUTEX(name) mutable boost::shared_mutex name
 #define CM_LOCK_RW_MUTEX_READ(name) boost::shared_lock<boost::shared_mutex> cmnameLock(name)
 #define CM_LOCK_RW_MUTEX_READ(name) boost::shared_lock<boost::shared_mutex> cmnameLock(name)
 #define CM_LOCK_RW_MUTEX_WRITE(name) boost::unique_lock<boost::shared_mutex> cmnameLock(name)
 #define CM_LOCK_RW_MUTEX_WRITE(name) boost::unique_lock<boost::shared_mutex> cmnameLock(name)
-// Thread-local pointer
-#define CM_THREAD_POINTER(T, var) boost::thread_specific_ptr<T> var
-#define CM_THREAD_POINTER_INIT(var) var(&deletePtr)
-#define CM_THREAD_POINTER_VAR(T, var) boost::thread_specific_ptr<T> var (&deletePtr<T>)
-#define CM_THREAD_POINTER_SET(var, expr) var.reset(expr)
-#define CM_THREAD_POINTER_GET(var) var.get()
-#define CM_THREAD_POINTER_DELETE(var) var.reset(0)
 // Thread objects and related functions
 // Thread objects and related functions
 #define CM_THREAD_TYPE boost::thread
 #define CM_THREAD_TYPE boost::thread
 #define CM_THREAD_CREATE(name, worker) boost::thread* name = new (CamelotEngine::MemoryAllocator<CamelotEngine::GenAlloc>::allocate(sizeof(boost::thread))) boost::thread(worker);
 #define CM_THREAD_CREATE(name, worker) boost::thread* name = new (CamelotEngine::MemoryAllocator<CamelotEngine::GenAlloc>::allocate(sizeof(boost::thread))) boost::thread(worker);
@@ -93,7 +85,6 @@ THE SOFTWARE
 #define CM_LOCK_MUTEX_NAMED(mutexName, lockName)
 #define CM_LOCK_MUTEX_NAMED(mutexName, lockName)
 #define CM_AUTO_SHARED_MUTEX
 #define CM_AUTO_SHARED_MUTEX
 #define CM_LOCK_AUTO_SHARED_MUTEX
 #define CM_LOCK_AUTO_SHARED_MUTEX
-#define CM_DELETE_AUTO_SHARED_MUTEX
 #define CM_COPY_AUTO_SHARED_MUTEX(from)
 #define CM_COPY_AUTO_SHARED_MUTEX(from)
 #define CM_SET_AUTO_SHARED_MUTEX_NULL
 #define CM_SET_AUTO_SHARED_MUTEX_NULL
 #define CM_MUTEX_CONDITIONAL(name) if(true)
 #define CM_MUTEX_CONDITIONAL(name) if(true)
@@ -106,12 +97,6 @@ THE SOFTWARE
 #define CM_THREAD_WAIT(sync, lock) 
 #define CM_THREAD_WAIT(sync, lock) 
 #define CM_THREAD_NOTIFY_ONE(sync) 
 #define CM_THREAD_NOTIFY_ONE(sync) 
 #define CM_THREAD_NOTIFY_ALL(sync) 
 #define CM_THREAD_NOTIFY_ALL(sync) 
-#define CM_THREAD_POINTER(T, var) T* var
-#define CM_THREAD_POINTER_INIT(var) var(0)
-#define CM_THREAD_POINTER_VAR(T, var) T* var = 0
-#define CM_THREAD_POINTER_SET(var, expr) var = expr
-#define CM_THREAD_POINTER_GET(var) var
-#define CM_THREAD_POINTER_DELETE(var) { delete var; var = 0; }
 #define CM_THREAD_SLEEP(ms)
 #define CM_THREAD_SLEEP(ms)
 #define CM_THREAD_ID_TYPE UINT32
 #define CM_THREAD_ID_TYPE UINT32
 #define CM_THREAD_WORKER_INHERIT
 #define CM_THREAD_WORKER_INHERIT

+ 9 - 14
CamelotUtility/Source/CmDataStream.cpp

@@ -469,7 +469,7 @@ namespace CamelotEngine
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    FileDataStream::FileDataStream(std::ifstream* s, bool freeOnClose)
+    FileDataStream::FileDataStream(std::shared_ptr<std::ifstream> s, bool freeOnClose)
         : DataStream(), mpInStream(s), mpFStreamRO(s), mpFStream(0), mFreeOnClose(freeOnClose)
         : DataStream(), mpInStream(s), mpFStreamRO(s), mpFStream(0), mFreeOnClose(freeOnClose)
     {
     {
         // calculate the size
         // calculate the size
@@ -480,7 +480,7 @@ namespace CamelotEngine
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     FileDataStream::FileDataStream(const String& name, 
     FileDataStream::FileDataStream(const String& name, 
-        std::ifstream* s, bool freeOnClose)
+        std::shared_ptr<std::ifstream> s, bool freeOnClose)
         : DataStream(name), mpInStream(s), mpFStreamRO(s), mpFStream(0), mFreeOnClose(freeOnClose)
         : DataStream(name), mpInStream(s), mpFStreamRO(s), mpFStream(0), mFreeOnClose(freeOnClose)
     {
     {
         // calculate the size
         // calculate the size
@@ -491,7 +491,7 @@ namespace CamelotEngine
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     FileDataStream::FileDataStream(const String& name, 
     FileDataStream::FileDataStream(const String& name, 
-        std::ifstream* s, size_t inSize, bool freeOnClose)
+        std::shared_ptr<std::ifstream> s, size_t inSize, bool freeOnClose)
         : DataStream(name), mpInStream(s), mpFStreamRO(s), mpFStream(0), mFreeOnClose(freeOnClose)
         : DataStream(name), mpInStream(s), mpFStreamRO(s), mpFStream(0), mFreeOnClose(freeOnClose)
     {
     {
         // Size is passed in
         // Size is passed in
@@ -499,7 +499,7 @@ namespace CamelotEngine
 		determineAccess();
 		determineAccess();
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	FileDataStream::FileDataStream(std::fstream* s, bool freeOnClose)
+	FileDataStream::FileDataStream(std::shared_ptr<std::fstream> s, bool freeOnClose)
 		: DataStream(false), mpInStream(s), mpFStreamRO(0), mpFStream(s), mFreeOnClose(freeOnClose)
 		: DataStream(false), mpInStream(s), mpFStreamRO(0), mpFStream(s), mFreeOnClose(freeOnClose)
 	{
 	{
 		// writeable!
 		// writeable!
@@ -512,7 +512,7 @@ namespace CamelotEngine
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	FileDataStream::FileDataStream(const String& name, 
 	FileDataStream::FileDataStream(const String& name, 
-		std::fstream* s, bool freeOnClose)
+		std::shared_ptr<std::fstream> s, bool freeOnClose)
 		: DataStream(name, false), mpInStream(s), mpFStreamRO(0), mpFStream(s), mFreeOnClose(freeOnClose)
 		: DataStream(name, false), mpInStream(s), mpFStreamRO(0), mpFStream(s), mFreeOnClose(freeOnClose)
 	{
 	{
 		// writeable!
 		// writeable!
@@ -524,7 +524,7 @@ namespace CamelotEngine
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	FileDataStream::FileDataStream(const String& name, 
 	FileDataStream::FileDataStream(const String& name, 
-		std::fstream* s, size_t inSize, bool freeOnClose)
+		std::shared_ptr<std::fstream> s, size_t inSize, bool freeOnClose)
 		: DataStream(name, false), mpInStream(s), mpFStreamRO(0), mpFStream(s), mFreeOnClose(freeOnClose)
 		: DataStream(name, false), mpInStream(s), mpFStreamRO(0), mpFStream(s), mFreeOnClose(freeOnClose)
 	{
 	{
 		// writeable!
 		// writeable!
@@ -678,14 +678,9 @@ namespace CamelotEngine
 
 
             if (mFreeOnClose)
             if (mFreeOnClose)
             {
             {
-                // delete the stream too
-				if (mpFStreamRO)
-					delete mpFStreamRO;
-				if (mpFStream)
-					delete mpFStream;
-				mpInStream = 0;
-				mpFStreamRO = 0; 
-				mpFStream = 0; 
+				mpInStream = nullptr;
+				mpFStreamRO = nullptr; 
+				mpFStream = nullptr; 
             }
             }
         }
         }
     }
     }

+ 9 - 19
CamelotUtility/Source/CmFileSystem.cpp

@@ -38,35 +38,29 @@ namespace CamelotEngine
 		// Always open in binary mode
 		// Always open in binary mode
 		// Also, always include reading
 		// Also, always include reading
 		std::ios::openmode mode = std::ios::in | std::ios::binary;
 		std::ios::openmode mode = std::ios::in | std::ios::binary;
-		std::istream* baseStream = 0;
-		std::ifstream* roStream = 0;
-		std::fstream* rwStream = 0;
+		std::shared_ptr<std::istream> baseStream = 0;
+		std::shared_ptr<std::ifstream> roStream = 0;
+		std::shared_ptr<std::fstream> rwStream = 0;
 
 
 		if (!readOnly)
 		if (!readOnly)
 		{
 		{
 			mode |= std::ios::out;
 			mode |= std::ios::out;
-			rwStream = CM_NEW(std::fstream, ScratchAlloc) std::fstream();
+			rwStream = std::shared_ptr<std::fstream>(CM_NEW(std::fstream, ScratchAlloc) std::fstream(),
+				&MemAllocDeleter<std::fstream, ScratchAlloc>::deleter);
 			rwStream->open(fullPath.c_str(), mode);
 			rwStream->open(fullPath.c_str(), mode);
 			baseStream = rwStream;
 			baseStream = rwStream;
 		}
 		}
 		else
 		else
 		{
 		{
-			roStream = CM_NEW(std::ifstream, ScratchAlloc) std::ifstream();
+			roStream = std::shared_ptr<std::ifstream>(CM_NEW(std::ifstream, ScratchAlloc) std::ifstream(),
+				&MemAllocDeleter<std::ifstream, ScratchAlloc>::deleter);
 			roStream->open(fullPath.c_str(), mode);
 			roStream->open(fullPath.c_str(), mode);
 			baseStream = roStream;
 			baseStream = roStream;
 		}
 		}
 
 
 		// Should check ensure open succeeded, in case fail for some reason.
 		// Should check ensure open succeeded, in case fail for some reason.
 		if (baseStream->fail())
 		if (baseStream->fail())
-		{
-			if(roStream != nullptr)
-				CM_DELETE(roStream, std::ifstream, ScratchAlloc);
-
-			if(rwStream != nullptr)
-				CM_DELETE(rwStream, std::fstream, ScratchAlloc);
-
 			CM_EXCEPT(FileNotFoundException, "Cannot open file: " + fullPath);
 			CM_EXCEPT(FileNotFoundException, "Cannot open file: " + fullPath);
-		}
 
 
 		/// Construct return stream, tell it to delete on destroy
 		/// Construct return stream, tell it to delete on destroy
 		FileDataStream* stream = 0;
 		FileDataStream* stream = 0;
@@ -88,17 +82,13 @@ namespace CamelotEngine
 		// Always open in binary mode
 		// Always open in binary mode
 		// Also, always include reading
 		// Also, always include reading
 		std::ios::openmode mode = std::ios::out | std::ios::binary;
 		std::ios::openmode mode = std::ios::out | std::ios::binary;
-		std::fstream* rwStream = CM_NEW(std::fstream, ScratchAlloc) std::fstream();
+		std::shared_ptr<std::fstream> rwStream(CM_NEW(std::fstream, ScratchAlloc) std::fstream(),
+			&MemAllocDeleter<std::fstream, ScratchAlloc>::deleter);
 		rwStream->open(fullPath.c_str(), mode);
 		rwStream->open(fullPath.c_str(), mode);
 
 
 		// Should check ensure open succeeded, in case fail for some reason.
 		// Should check ensure open succeeded, in case fail for some reason.
 		if (rwStream->fail())
 		if (rwStream->fail())
-		{
-			if(rwStream != nullptr)
-				CM_DELETE(rwStream, std::fstream, ScratchAlloc); ;
-
 			CM_EXCEPT(FileNotFoundException, "Cannot open file: " + fullPath);
 			CM_EXCEPT(FileNotFoundException, "Cannot open file: " + fullPath);
-		}
 
 
 		/// Construct return stream, tell it to delete on destroy
 		/// Construct return stream, tell it to delete on destroy
 		FileDataStream* stream = CM_NEW(FileDataStream, ScratchAlloc) FileDataStream(fullPath, rwStream, 0, true);
 		FileDataStream* stream = CM_NEW(FileDataStream, ScratchAlloc) FileDataStream(fullPath, rwStream, 0, true);

+ 1 - 1
CamelotUtility/Source/CmLog.cpp

@@ -34,7 +34,7 @@ namespace CamelotEngine
 	void Log::clear()
 	void Log::clear()
 	{
 	{
 		for(auto iter = mEntries.begin(); iter != mEntries.end(); ++iter)
 		for(auto iter = mEntries.begin(); iter != mEntries.end(); ++iter)
-			delete *iter;
+			CM_DELETE(*iter, LogEntry, PoolAlloc);
 
 
 		mEntries.clear();
 		mEntries.clear();