From d6d72e6b031d18e7ea42fc5aba2ee146316b4935 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 10 May 2024 10:14:04 +0200 Subject: [PATCH] registry: assert on user entity storage - close #1143 --- src/entt/entity/registry.hpp | 2 ++ test/entt/entity/registry.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index ff42863de..49dba31b1 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -244,6 +244,7 @@ class basic_registry { static_assert(std::is_same_v>, "Non-decayed types not allowed"); if constexpr(std::is_same_v) { + ENTT_ASSERT(id == type_hash::value(), "User entity storage not allowed"); return entities; } else { auto &cpool = pools[id]; @@ -272,6 +273,7 @@ class basic_registry { static_assert(std::is_same_v>, "Non-decayed types not allowed"); if constexpr(std::is_same_v) { + ENTT_ASSERT(id == type_hash::value(), "User entity storage not allowed"); return &entities; } else { if(const auto it = pools.find(id); it != pools.cend()) { diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index d1c1f28aa..7d26b12c1 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -525,6 +525,9 @@ ENTT_DEBUG_TEST(RegistryDeathTest, Storage) { ASSERT_DEATH(registry.storage("other"_hs), ""); ASSERT_DEATH(std::as_const(registry).storage("other"_hs), ""); + + ASSERT_DEATH(registry.storage("other"_hs), ""); + ASSERT_DEATH(std::as_const(registry).storage("other"_hs), ""); } TEST(Registry, Identifiers) {