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;