From eb9a666b721d6626c38b00b678e0dab49cb88e5b Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:19:06 +0200 Subject: [PATCH 1/7] Add delete macro --- include/macros.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 include/macros.h diff --git a/include/macros.h b/include/macros.h new file mode 100644 index 0000000..5c6ed02 --- /dev/null +++ b/include/macros.h @@ -0,0 +1,6 @@ +#ifndef MACROS_H +#define MACROS_H + +#define IF_NOT_NULL_DELETE(a) (a ? delete a : void()) + +#endif \ No newline at end of file From d4e2dd4bcbf299fdfb3344ff63db0872cbfb1752 Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:48:57 +0200 Subject: [PATCH 2/7] Add manual delete for all entity members --- include/engine/entity.h | 4 +++- src/engine/entity.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/engine/entity.h b/include/engine/entity.h index 6e025a7..20f72bc 100644 --- a/include/engine/entity.h +++ b/include/engine/entity.h @@ -20,6 +20,8 @@ #include "engine/physics/phxbox.h" #include "engine/physics/point.h" +#include "macros.h" + namespace Engine { class InputHandler; @@ -38,7 +40,7 @@ class Entity { public: Entity(); Entity(std::string name); - ~Entity() = default; + virtual ~Entity(); void addPoint(); Point* getPoint(); diff --git a/src/engine/entity.cpp b/src/engine/entity.cpp index d805913..0991ba0 100644 --- a/src/engine/entity.cpp +++ b/src/engine/entity.cpp @@ -7,6 +7,12 @@ Engine::Entity::Entity() { this->sprite = NULL; } +Engine::Entity::~Entity() { + IF_NOT_NULL_DELETE(this->point); + IF_NOT_NULL_DELETE(this->sprite); + IF_NOT_NULL_DELETE(this->phxbox); +} + Engine::Entity::Entity(std::string name) : Entity() { this->name = name; } void Engine::Entity::addPoint() { From 68acd1a891f0cf36b15f1f2da3ed7725766df119 Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:49:18 +0200 Subject: [PATCH 3/7] Add point destructor --- include/engine/physics/point.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/engine/physics/point.h b/include/engine/physics/point.h index 6dd2aab..c6fa249 100644 --- a/include/engine/physics/point.h +++ b/include/engine/physics/point.h @@ -39,6 +39,7 @@ class Point { PhxParam getParam(); Point(/* args */) = default; + ~Point(){}; Point(PhxParam phxParam) { this->phxParam = phxParam; }; void setMass(double mass) { this->phxParam.mass = mass; }; From d45d2b7fcf3aee25e6ee2243f9331ba9db84559d Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:50:13 +0200 Subject: [PATCH 4/7] Add inputHandler destructor --- include/engine/input/input_handler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/engine/input/input_handler.h b/include/engine/input/input_handler.h index 4741d57..45981f3 100644 --- a/include/engine/input/input_handler.h +++ b/include/engine/input/input_handler.h @@ -34,7 +34,7 @@ struct Keybind { class InputHandler { public: InputHandler(/* args */) = default; - ~InputHandler() = default; + ~InputHandler(){}; void setOwner(Entity* entity) { this->owner = entity; }; virtual void doInput(int actionId){}; From d2cd3235cf7d452de9b372118e0e30ac6300265c Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:50:28 +0200 Subject: [PATCH 5/7] Add box and intersection destructors --- include/engine/box/box.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/engine/box/box.h b/include/engine/box/box.h index c6b4fa1..40d075c 100644 --- a/include/engine/box/box.h +++ b/include/engine/box/box.h @@ -25,6 +25,7 @@ template struct Intersection { std::pair intersectionVector = std::make_pair( 0, 0); // Vector start from intersecting, towards intersected Intersection() = default; + virtual ~Intersection(){}; }; /** @@ -40,7 +41,7 @@ template class Box { public: Box() = default; - ~Box() = default; + virtual ~Box(){}; std::pair* getPos() { return pos; }; std::vector> getVertices() { From da5a2eb603fe20170652ae55d2a28fbbb700da53 Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:51:19 +0200 Subject: [PATCH 6/7] Add PhxBox destructor --- include/engine/physics/phxbox.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/engine/physics/phxbox.h b/include/engine/physics/phxbox.h index 8d67ac2..53a29fe 100644 --- a/include/engine/physics/phxbox.h +++ b/include/engine/physics/phxbox.h @@ -36,6 +36,7 @@ class PhxBox { STATIC ///< Cannot be pushed }; PhxBox() = default; + ~PhxBox(){}; Box* getBox() { return this->box; }; From 79af224bbb17dd807263f82cbe63e7967cebc391 Mon Sep 17 00:00:00 2001 From: "g.brivady" <12777915+gbrivady@users.noreply.github.com> Date: Fri, 9 Jun 2023 21:53:18 +0200 Subject: [PATCH 7/7] Add Universe destructor --- include/engine/universe_master.h | 1 + src/engine/universe_master.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/engine/universe_master.h b/include/engine/universe_master.h index d93d226..cd7fb23 100644 --- a/include/engine/universe_master.h +++ b/include/engine/universe_master.h @@ -48,6 +48,7 @@ typedef std::vector InpHdlTable; class UniverseMaster { public: UniverseMaster(/* args */) = default; + ~UniverseMaster(); void linkWindow(sf::RenderWindow* p_window) { this->window = p_window; }; diff --git a/src/engine/universe_master.cpp b/src/engine/universe_master.cpp index 915dd99..bcaaeab 100644 --- a/src/engine/universe_master.cpp +++ b/src/engine/universe_master.cpp @@ -5,6 +5,15 @@ using namespace Engine; +Engine::UniverseMaster::~UniverseMaster() { + for (Entity* entity : this->allEntity) { + delete entity; + } + for (InputHandler* handle : this->allInpHdl) { + delete handle; + } +} + void Engine::UniverseMaster::addEntity(Entity* entity) { this->allEntity.push_back(entity); Point* point = entity->getPoint();