]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Actually call component destructors on reset().
authorAlec Thomas <alec@swapoff.org>
Mon, 20 Oct 2014 23:40:44 +0000 (10:40 +1100)
committerAlec Thomas <alec@swapoff.org>
Mon, 20 Oct 2014 23:41:20 +0000 (10:41 +1100)
entityx/Entity.cc
entityx/Entity.h
entityx/help/Pool.h

index e81ae802bd47bd3f25e99b8ebe0a3da28c2adac2..463e6b34b0e974a6b19f513f2d87306b76e78b83 100644 (file)
@@ -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;
   }
index 7032ab179ca83188991ff47d69f6cbaa7f498410..b749c4ced6344d56afe8419b8009724091732daf 100644 (file)
@@ -552,6 +552,7 @@ class EntityManager : entityx::help::NonCopyable {
   ComponentHandle<C> 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<C> *pool = accomodate_component<C>();
index 7b1ca1917d523ef2fd17eb5c66966b3853ff6b51..f217ec25b0bb3f1fbd4af7e4ff21482f674b7561 100644 (file)
@@ -81,7 +81,9 @@ template <typename T, std::size_t ChunkSize = 8192>
 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_);