From: Alec Thomas Date: Mon, 20 Oct 2014 23:40:44 +0000 (+1100) Subject: Actually call component destructors on reset(). X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=d1c9572526291a16db73e53edfb378af7c50c784;p=clyne%2Fentityx.git Actually call component destructors on reset(). --- 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_);