foxygit / fake-08-xbox360 Log in
commit 704181d8940c0fa9575d75343e7d8ca262c25f37
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Mon Apr 20 21:20:25 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Mon Apr 20 21:20:25 2020 -0600

    Call delete on objects that have been 'new'ed
---
 source/console.cpp | 13 +++++++++++--
 source/console.h   |  1 +
 source/main.cpp    | 13 +++++++------
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/source/console.cpp b/source/console.cpp
index 3b01c45..e76d498 100644
--- a/source/console.cpp
+++ b/source/console.cpp
@@ -32,11 +32,20 @@ Console::Console(){
     //initGlobalApi(_graphics);
 }

+Console::~Console(){
+    delete _graphics;
+    delete _input;
+
+    if (_loadedCart){
+        delete _loadedCart;
+    }
+}
+
 void Console::LoadCart(std::string filename){
     Logger::Write("Calling Cart Constructor\n");
-    Cart cart = Cart(filename);
+    Cart *cart = new Cart(filename);

-    _loadedCart = &cart;
+    _loadedCart = cart;

     _graphics->setSpriteSheet(_loadedCart->SpriteSheetString);

diff --git a/source/console.h b/source/console.h
index 669fabc..e071cfd 100644
--- a/source/console.h
+++ b/source/console.h
@@ -17,6 +17,7 @@ class Console {

     public:
     Console();
+    ~Console();

     void LoadCart(std::string filename);

diff --git a/source/main.cpp b/source/main.cpp
index e510270..af1f893 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -62,7 +62,7 @@ int main(int argc, char* argv[])
 	Logger::Write("gfxInitDefault()\n");

 	Logger::Write("initializing Console\n");
-	Console console;
+	Console *console = new Console();
 	Logger::Write("initialized console\n");

 	//test or not both hardcoded to loading test cart as of now
@@ -71,7 +71,7 @@ int main(int argc, char* argv[])
 	consoleInit(GFX_BOTTOM, NULL);

 	Logger::Write("Loading cart\n");
-	console.LoadCart("testcart.p8");
+	console->LoadCart("testcart.p8");
 	Logger::Write("Cart Loaded\n");

 	#else
@@ -112,15 +112,15 @@ int main(int argc, char* argv[])
 		//cart draw
 		//_draw();

-		console.UpdateAndDraw(frames, p8kDown, p8kHeld);
+		console->UpdateAndDraw(frames, p8kDown, p8kHeld);

 		//send pico 8 screen to framebuffer
-		console.FlipBuffer(fb);
+		console->FlipBuffer(fb);

 		// Flush and swap framebuffers
+		//possibly pass this as a function to flip buffer to support more platforms?
 		gfxFlushBuffers();
 		gfxSwapBuffers();
-
 		gspWaitForVBlank();

     	frames++;
@@ -128,7 +128,8 @@ int main(int argc, char* argv[])


 	Logger::Write("Turning off console and exiting logger\n");
-	console.TurnOff();
+	console->TurnOff();
+	delete console;
 	Logger::Exit();
 	gfxExit();
 	return 0;