diff --git a/src/entt/entity/mixin.hpp b/src/entt/entity/mixin.hpp index 044098f0f..2dab36c63 100644 --- a/src/entt/entity/mixin.hpp +++ b/src/entt/entity/mixin.hpp @@ -29,21 +29,25 @@ class sigh_mixin final: public Type { using underlying_iterator = typename Type::base_type::basic_iterator; void pop(underlying_iterator first, underlying_iterator last) final { - ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry"); + if(destruction.empty()) { + Type::pop(first, last); + } else { + ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry"); - for(; first != last; ++first) { - const auto entt = *first; - destruction.publish(*owner, entt); - const auto it = Type::find(entt); - Type::pop(it, it + 1u); + for(; first != last; ++first) { + const auto entt = *first; + destruction.publish(*owner, entt); + const auto it = Type::find(entt); + Type::pop(it, it + 1u); + } } } underlying_iterator try_emplace(const typename Type::entity_type entt, const bool force_back, const void *value) final { - ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry"); const auto it = Type::try_emplace(entt, force_back, value); if(it != Type::base_type::end()) { + ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry"); construction.publish(*owner, *it); } @@ -210,11 +214,14 @@ public: */ template void insert(It first, It last, Args &&...args) { - ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry"); Type::insert(first, last, std::forward(args)...); - for(auto it = construction.empty() ? last : first; it != last; ++it) { - construction.publish(*owner, *it); + if(!construction.empty()) { + ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry"); + + for(; first != last; ++first) { + construction.publish(*owner, *first); + } } } diff --git a/test/entt/entity/sigh_mixin.cpp b/test/entt/entity/sigh_mixin.cpp index 0d8bfd382..f02ba3ac0 100644 --- a/test/entt/entity/sigh_mixin.cpp +++ b/test/entt/entity/sigh_mixin.cpp @@ -41,6 +41,17 @@ TEST(SighMixin, GenericType) { counter on_destroy{}; pool.bind(entt::forward_as_any(registry)); + + ASSERT_TRUE(pool.empty()); + + pool.insert(entities, entities + 1u); + pool.erase(entities[0u]); + + ASSERT_TRUE(pool.empty()); + + ASSERT_EQ(on_construct.value, 0); + ASSERT_EQ(on_destroy.value, 0); + pool.on_construct().connect<&listener>(on_construct); pool.on_destroy().connect<&listener>(on_destroy);