Browse Source

sigh_storage_mixin: always trigger an emplace request notification (in sync with unbalanced destroy)

Michele Caini 4 years ago
parent
commit
72440ab937
2 changed files with 9 additions and 8 deletions
  1. 1 4
      src/entt/entity/storage.hpp
  2. 8 4
      test/entt/entity/sigh_storage_mixin.cpp

+ 1 - 4
src/entt/entity/storage.hpp

@@ -929,10 +929,7 @@ class sigh_storage_mixin final: public Type {
     void try_emplace(const typename Type::entity_type entt, const void *value) final {
         ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
         Type::try_emplace(entt, value);
-
-        if(Type::contains(entt)) {
-            construction.publish(*owner, entt);
-        }
+        construction.publish(*owner, entt);
     }
 
 public:

+ 8 - 4
test/entt/entity/sigh_storage_mixin.cpp

@@ -183,7 +183,8 @@ TEST(SighStorageMixin, NonDefaultConstructibleType) {
 
     pool.emplace(entities[1u], 3);
 
-    ASSERT_EQ(on_construct.value, 1);
+    ASSERT_EQ(pool.size(), 1u);
+    ASSERT_EQ(on_construct.value, 2);
     ASSERT_EQ(on_destroy.value, 0);
     ASSERT_FALSE(pool.empty());
 
@@ -192,7 +193,8 @@ TEST(SighStorageMixin, NonDefaultConstructibleType) {
 
     base.erase(entities[1u]);
 
-    ASSERT_EQ(on_construct.value, 1);
+    ASSERT_EQ(pool.size(), 0u);
+    ASSERT_EQ(on_construct.value, 2);
     ASSERT_EQ(on_destroy.value, 1);
     ASSERT_TRUE(pool.empty());
 
@@ -204,7 +206,8 @@ TEST(SighStorageMixin, NonDefaultConstructibleType) {
 
     pool.insert(std::begin(entities), std::end(entities), 3);
 
-    ASSERT_EQ(on_construct.value, 3);
+    ASSERT_EQ(pool.size(), 2u);
+    ASSERT_EQ(on_construct.value, 6);
     ASSERT_EQ(on_destroy.value, 1);
     ASSERT_FALSE(pool.empty());
 
@@ -213,7 +216,8 @@ TEST(SighStorageMixin, NonDefaultConstructibleType) {
 
     pool.erase(std::begin(entities), std::end(entities));
 
-    ASSERT_EQ(on_construct.value, 3);
+    ASSERT_EQ(pool.size(), 0u);
+    ASSERT_EQ(on_construct.value, 6);
     ASSERT_EQ(on_destroy.value, 3);
     ASSERT_TRUE(pool.empty());
 }