diff --git a/TODO b/TODO index 98d5e82e4..e825d200f 100644 --- a/TODO +++ b/TODO @@ -12,6 +12,7 @@ DOC: WIP: * add storage getter for filters to views and groups +* exploit the tombstone mechanism to allow enabling/disabling entities (see bump, compact and clear for further details) * emitter: runtime handlers, allocator support (ready for both already) * view: no storage_traits dependency -> use storage instead of components for the definition * basic_storage::bind for cross-registry setups (see and remove todo from entity_copy.cpp) diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index b4c601f53..7b7200062 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -671,6 +671,7 @@ public: * @param entt A valid identifier. */ void bump(const entity_type entt) { + ENTT_ASSERT(entity_traits::to_version(entt) != entity_traits::to_version(tombstone), "Cannot set the tombstone version"); auto &entity = sparse_ref(entt); entity = entity_traits::combine(entity_traits::to_integral(entity), entity_traits::to_integral(entt)); packed[static_cast(entity_traits::to_entity(entity))] = entt; diff --git a/test/entt/entity/sparse_set.cpp b/test/entt/entity/sparse_set.cpp index 99f600c74..172949189 100644 --- a/test/entt/entity/sparse_set.cpp +++ b/test/entt/entity/sparse_set.cpp @@ -335,11 +335,15 @@ TEST(SparseSet, Bump) { } TEST(SparseSetDeathTest, Bump) { + using traits_type = entt::entt_traits; + entt::sparse_set set{entt::deletion_policy::in_place}; + set.emplace(entt::entity{3}); ASSERT_DEATH(set.bump(entt::null), ""); ASSERT_DEATH(set.bump(entt::tombstone), ""); ASSERT_DEATH(set.bump(entt::entity{42}), ""); + ASSERT_DEATH(set.bump(traits_type::construct(traits_type::to_entity(entt::entity{3}), traits_type::to_entity(entt::tombstone))), ""); } TEST(SparseSet, Insert) {