]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Only delete assigned components.
authorAlec Thomas <alec@swapoff.org>
Thu, 15 May 2014 16:56:25 +0000 (12:56 -0400)
committerAlec Thomas <alec@swapoff.org>
Thu, 15 May 2014 16:56:25 +0000 (12:56 -0400)
Fixes #31.

entityx/Entity.h
entityx/Entity_test.cc

index 7362f69a64576f4e126e33c7fa1404d327dc640e..5f51b50129385d668351beb4dd05454945dc9a3f 100644 (file)
@@ -456,9 +456,12 @@ class EntityManager : entityx::help::NonCopyable {
   void destroy(Entity::Id entity) {
     assert_valid(entity);
     int index = entity.index();
+    auto mask = entity_component_mask_[entity.index()];
     event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity));
-    for (BasePool *pool : component_pools_) {
-      if (pool) pool->destroy(index);
+    for (size_t i = 0; i < component_pools_.size(); i++) {
+      BasePool *pool = component_pools_[i];
+      if (pool && mask.test(i))
+        pool->destroy(index);
     }
     entity_component_mask_[index] = 0;
     entity_version_[index]++;
index f40a9bc23c0d69916c64079727f7474eda12a319..1f87473ff95c051a83ec45c7ad21716f6968d181 100644 (file)
@@ -449,3 +449,10 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestComponentHandleInvalidatedWhenCompon
   a.remove<Position>();
   REQUIRE(!position);
 }
+
+TEST_CASE_METHOD(EntityManagerFixture, "TestDeleteEntityWithNoComponents") {
+  Entity a = em.create();
+  a.assign<Position>(1, 2);
+  Entity b = em.create();
+  b.destroy();
+}