registry: assert on user entity storage - close #1143

This commit is contained in:
Michele Caini
2024-05-10 10:14:04 +02:00
parent 35ebf5c413
commit d6d72e6b03
2 changed files with 5 additions and 0 deletions
+2
View File
@@ -244,6 +244,7 @@ class basic_registry {
static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Non-decayed types not allowed");
if constexpr(std::is_same_v<Type, entity_type>) {
ENTT_ASSERT(id == type_hash<Type>::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<Type, std::decay_t<Type>>, "Non-decayed types not allowed");
if constexpr(std::is_same_v<Type, entity_type>) {
ENTT_ASSERT(id == type_hash<Type>::value(), "User entity storage not allowed");
return &entities;
} else {
if(const auto it = pools.find(id); it != pools.cend()) {
+3
View File
@@ -525,6 +525,9 @@ ENTT_DEBUG_TEST(RegistryDeathTest, Storage) {
ASSERT_DEATH(registry.storage<int>("other"_hs), "");
ASSERT_DEATH(std::as_const(registry).storage<int>("other"_hs), "");
ASSERT_DEATH(registry.storage<entt::entity>("other"_hs), "");
ASSERT_DEATH(std::as_const(registry).storage<entt::entity>("other"_hs), "");
}
TEST(Registry, Identifiers) {