From 4df0f4e1e43090d07e06d0c285121116326b30d7 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 27 Jun 2024 15:53:51 +0300 Subject: [PATCH] fix destroyed entities validation --- src/objects/Entities.cpp | 2 +- src/objects/Entities.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index ce1cc171..291ac1fd 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -34,7 +34,7 @@ entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos) { } void Entities::clean() { - for (auto it = entities.begin(); it != entities.end(); ++it) { + for (auto it = entities.begin(); it != entities.end();) { if (registry.valid(it->second)) { ++it; } else { diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index 5d684a8b..1e020605 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -85,7 +85,7 @@ public: std::optional get(entityid_t id) { const auto& found = entities.find(id); - if (found != entities.end()) { + if (found != entities.end() && registry.valid(found->second)) { return Entity(id, registry, found->second); } return std::nullopt;