From d1c9572526291a16db73e53edfb378af7c50c784 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Tue, 21 Oct 2014 10:40:44 +1100 Subject: Actually call component destructors on reset(). --- entityx/Entity.cc | 1 + entityx/Entity.h | 1 + entityx/help/Pool.h | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/entityx/Entity.cc b/entityx/Entity.cc index e81ae80..463e6b3 100644 --- a/entityx/Entity.cc +++ b/entityx/Entity.cc @@ -39,6 +39,7 @@ EntityManager::~EntityManager() { } void EntityManager::reset() { + for (Entity entity : entities_for_debugging()) entity.destroy(); for (BasePool *pool : component_pools_) { if (pool) delete pool; } diff --git a/entityx/Entity.h b/entityx/Entity.h index 7032ab1..b749c4c 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -552,6 +552,7 @@ class EntityManager : entityx::help::NonCopyable { ComponentHandle assign(Entity::Id id, Args && ... args) { assert_valid(id); const BaseComponent::Family family = C::family(); + assert(!entity_component_mask_[id.index()].test(family)); // Placement new into the component pool. Pool *pool = accomodate_component(); diff --git a/entityx/help/Pool.h b/entityx/help/Pool.h index 7b1ca19..f217ec2 100644 --- a/entityx/help/Pool.h +++ b/entityx/help/Pool.h @@ -81,7 +81,9 @@ template class Pool : public BasePool { public: Pool() : BasePool(sizeof(T), ChunkSize) {} - virtual ~Pool() {} + virtual ~Pool() { + // Component destructors *must* be called by owner. + } virtual void destroy(std::size_t n) override { assert(n < size_); -- cgit v1.2.3