From 72440ab9375fca152aaa47acc5d95fbae9bf982a Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 10 Jan 2022 00:23:18 +0100 Subject: [PATCH] sigh_storage_mixin: always trigger an emplace request notification (in sync with unbalanced destroy) --- src/entt/entity/storage.hpp | 5 +---- test/entt/entity/sigh_storage_mixin.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 129571a34..f57d02f64 100644 --- a/src/entt/entity/storage.hpp +++ b/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: diff --git a/test/entt/entity/sigh_storage_mixin.cpp b/test/entt/entity/sigh_storage_mixin.cpp index 7edbbfd2a..04f0fabbd 100644 --- a/test/entt/entity/sigh_storage_mixin.cpp +++ b/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()); }