changeset 67:8e7ebab350e7

Clean up memory leaks
author koryspansel
date Fri, 07 Oct 2011 01:15:28 -0700
parents f7095bce01cf
children c4ece16cf995
files LightClone/Source/ActionPanel.cpp LightClone/Source/ActionPanel.h LightClone/Source/Core.h LightClone/Source/GuiEventMap.cpp LightClone/Source/GuiEventMap.h LightClone/Source/GuiInterface.cpp LightClone/Source/GuiInterface.h LightClone/Source/Loader.cpp LightClone/Source/Main.cpp LightClone/Source/Util.cpp LightClone/Source/World.cpp LightClone/ToDo.txt
diffstat 12 files changed, 72 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/Source/ActionPanel.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/ActionPanel.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -18,6 +18,14 @@
 }
 
 /*
+ * ActionPanel
+ */
+ActionPanel::~ActionPanel()
+{
+	delete[] pSlot;
+}
+
+/*
  * Initialize
  */
 ErrorCode ActionPanel::Initialize(ServiceProvider* pServiceProvider)
--- a/LightClone/Source/ActionPanel.h	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/ActionPanel.h	Fri Oct 07 01:15:28 2011 -0700
@@ -63,6 +63,11 @@
 	ActionPanel(uint32 nWidth, uint32 nHeight);
 
 	/*
+	 * ActionPanel
+	 */
+	~ActionPanel();
+
+	/*
 	 * Initialize
 	 */
 	virtual ErrorCode Initialize(ServiceProvider* pServiceProvider);
--- a/LightClone/Source/Core.h	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/Core.h	Fri Oct 07 01:15:28 2011 -0700
@@ -5,11 +5,17 @@
 #ifndef __CORE_H__
 #define __CORE_H__
 
+#define CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+
 #include "Types.h"
 #include "Trace.h"
 #include "Debug.h"
 #include <d3d9.h>
 #include <d3dx9.h>
+#include <windows.h>
+#include <tchar.h>
 
 /*
  * WorldState
--- a/LightClone/Source/GuiEventMap.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/GuiEventMap.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -11,6 +11,20 @@
 {
 }
 
+/* 
+ * ~GuiEventMap
+ */
+GuiEventMap::~GuiEventMap()
+{
+	GuiEventHashMap::Iterator kEvent	= kMap.Begin();
+	GuiEventHashMap::Iterator kEventEnd	= kMap.End();
+
+	for(; kEvent != kEventEnd; ++kEvent)
+	{
+		delete *kEvent;
+	}
+}
+
 /*
  * Fire
  */
--- a/LightClone/Source/GuiEventMap.h	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/GuiEventMap.h	Fri Oct 07 01:15:28 2011 -0700
@@ -15,9 +15,14 @@
 class GuiEventMap
 {
 	/*
+	 * GuiEventHashMap
+	 */
+	typedef HashMap<FixedString<>, GuiEvent*, FixedString<>::Hash> GuiEventHashMap;
+
+	/*
 	 * kMap
 	 */
-	HashMap<FixedString<>, GuiEvent*, FixedString<>::Hash> kMap;
+	GuiEventHashMap kMap;
 
 public:
 
@@ -26,6 +31,11 @@
 	 */
 	GuiEventMap();
 
+	/* 
+	 * ~GuiEventMap
+	 */
+	~GuiEventMap();
+
 	/*
 	 * Subscribe
 	 */
--- a/LightClone/Source/GuiInterface.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/GuiInterface.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -14,6 +14,14 @@
 }
 
 /*
+ * ~GuiInterface
+ */
+GuiInterface::~GuiInterface()
+{
+	delete pCursor;
+}
+
+/*
  * Initialize
  */
 ErrorCode GuiInterface::Initialize(ServiceProvider* pServiceProvider)
@@ -54,6 +62,9 @@
  */
 void GuiInterface::Terminate()
 {
+	if(pCursor)
+		pCursor->Terminate();
+
 	GuiElement::Terminate();
 }
 
--- a/LightClone/Source/GuiInterface.h	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/GuiInterface.h	Fri Oct 07 01:15:28 2011 -0700
@@ -60,6 +60,11 @@
 	GuiInterface();
 
 	/*
+	 * ~GuiInterface
+	 */
+	~GuiInterface();
+
+	/*
 	 * Initialize
 	 */
 	ErrorCode Initialize(ServiceProvider* pServiceProvider);
--- a/LightClone/Source/Loader.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/Loader.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -27,17 +27,8 @@
  */
 Loader::~Loader()
 {
-	if(pType)
-	{
-		delete[] pType;
-		pType = 0;
-	}
-
-	if(pHeight)
-	{
-		delete[] pHeight;
-		pHeight = 0;
-	}
+	delete[] pType;
+	delete[] pHeight;
 }
 
 /*
@@ -45,17 +36,11 @@
  */
 ErrorCode Loader::Load(const char* pName)
 {
-	if(pType)
-	{
-		delete[] pType;
-		pType = 0;
-	}
+	delete[] pType;
+	pType = 0;
 
-	if(pHeight)
-	{
-		delete[] pHeight;
-		pHeight = 0;
-	}
+	delete[] pHeight;
+	pHeight = 0;
 
 	Buffer kBuffer = LoadFile(pName);
 
--- a/LightClone/Source/Main.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/Main.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -2,13 +2,13 @@
  * Main
  */
 
-#include <windows.h>
-#include <tchar.h>
 #include "Mediator.h"
-#include "VirtualMachine.h"
-#include "Trace.h"
 
 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
 {
+	#if defined(_DEBUG)
+	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+	#endif
+
 	return Mediator().Run();
 }
\ No newline at end of file
--- a/LightClone/Source/Util.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/Util.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -37,5 +37,5 @@
 		fclose(pFile);
 	}
 
-	return Buffer(pData, nSize);
+	return Buffer(pData, nSize, false);
 }
\ No newline at end of file
--- a/LightClone/Source/World.cpp	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/Source/World.cpp	Fri Oct 07 01:15:28 2011 -0700
@@ -226,9 +226,6 @@
  */
 ErrorCode World::InitializeInterface(ServiceProvider* pServiceProvider)
 {
-	//ResourceManager* pResourceManager = (ResourceManager*)pServiceProvider->GetService("ResourceManager");
-	//ASSERT(pResourceManager != NULL);
-
 	ErrorCode eCode = kInterface.Initialize(pServiceProvider);
 	if(eCode == Error_Success)
 	{
--- a/LightClone/ToDo.txt	Wed Oct 05 22:55:46 2011 -0700
+++ b/LightClone/ToDo.txt	Fri Oct 07 01:15:28 2011 -0700
@@ -11,4 +11,4 @@
 4.	Help interface
 
 Bugs:
-1.	Fix gui element destruction
+1.	Fix DX resource leaks
\ No newline at end of file