From 2dccd90166940ba32a2ec37044ba8db647d84a19 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 23 Dec 2022 16:53:51 +0100 Subject: [PATCH] handle: discard entity on destruction --- src/entt/entity/handle.hpp | 8 +++++--- test/entt/entity/handle.cpp | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/entt/entity/handle.hpp b/src/entt/entity/handle.hpp index fb4b8e720..210d95456 100644 --- a/src/entt/entity/handle.hpp +++ b/src/entt/entity/handle.hpp @@ -43,7 +43,9 @@ public: : entt{value}, it{from}, last{to} { - while(it != last && !it->second.contains(entt)) { ++it; } + while(it != last && !it->second.contains(entt)) { + ++it; + } } constexpr handle_storage_iterator &operator++() noexcept { @@ -196,7 +198,7 @@ struct basic_handle { /*! @brief Destroys the entity associated with a handle. */ void destroy() { - reg->destroy(entt); + reg->destroy(std::exchange(entt, null)); } /** @@ -204,7 +206,7 @@ struct basic_handle { * @param version A desired version upon destruction. */ void destroy(const version_type version) { - reg->destroy(entt, version); + reg->destroy(std::exchange(entt, null), version); } /** diff --git a/test/entt/entity/handle.cpp b/test/entt/entity/handle.cpp index 8cbf5dc7d..b7cab6644 100644 --- a/test/entt/entity/handle.cpp +++ b/test/entt/entity/handle.cpp @@ -83,8 +83,8 @@ TEST(BasicHandle, Destruction) { ASSERT_FALSE(handle); ASSERT_FALSE(handle.valid()); ASSERT_NE(handle.registry(), nullptr); - ASSERT_EQ(handle.entity(), entity); ASSERT_EQ(registry.current(entity), typename entt::registry::version_type{}); + ASSERT_EQ(handle.entity(), entt::entity{entt::null}); handle = entt::handle{registry, registry.create()}; @@ -98,8 +98,8 @@ TEST(BasicHandle, Destruction) { ASSERT_FALSE(handle); ASSERT_FALSE(handle.valid()); ASSERT_NE(handle.registry(), nullptr); - ASSERT_EQ(handle.entity(), entity); ASSERT_NE(registry.current(entity), typename entt::registry::version_type{}); + ASSERT_EQ(handle.entity(), entt::entity{entt::null}); } TEST(BasicHandle, Comparison) {