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() { 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/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){}; 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; }; 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; }; 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/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 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() { 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();