registry: allow creating pools during a destroy (close #853)

This commit is contained in:
Michele Caini
2022-03-09 09:56:58 +01:00
parent f6153f17ad
commit a431f5a674
2 changed files with 21 additions and 2 deletions

View File

@@ -701,8 +701,8 @@ public:
version_type destroy(const entity_type entity, const version_type version) {
ENTT_ASSERT(valid(entity), "Invalid entity");
for(auto &&curr: pools) {
curr.second->remove(entity);
for(size_type pos = pools.size(); pos; --pos) {
pools.begin()[pos - 1u].second->remove(entity);
}
return release_entity(entity, version);

View File

@@ -1395,6 +1395,25 @@ TEST(Registry, Signals) {
ASSERT_EQ(listener.last, entities[0u]);
}
TEST(Registry, SignalWhenDestroying) {
entt::registry registry;
const auto entity = registry.create();
registry.on_destroy<double>().connect<&entt::registry::remove<char>>();
registry.emplace<double>(entity);
registry.emplace<int>(entity);
ASSERT_NE(registry.storage(entt::type_id<double>().hash()), registry.storage().end());
ASSERT_NE(registry.storage(entt::type_id<int>().hash()), registry.storage().end());
ASSERT_EQ(registry.storage(entt::type_id<char>().hash()), registry.storage().end());
ASSERT_TRUE(registry.valid(entity));
registry.destroy(entity);
ASSERT_NE(registry.storage(entt::type_id<char>().hash()), registry.storage().end());
ASSERT_FALSE(registry.valid(entity));
}
TEST(Registry, Insert) {
entt::registry registry;
entt::entity entities[3u];