From 0e7f440a68931fd57591b95c3bacc69ad77b4a1f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 15 Jul 2024 02:04:53 +0300 Subject: [PATCH] add UID usage check in Entites::spawn --- src/objects/Entities.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index 27e6aef7..75d9d975 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -17,6 +17,7 @@ #include "../logic/scripting/scripting.hpp" #include "../engine.hpp" +#include #include static debug::Logger logger("entities"); @@ -75,13 +76,22 @@ entityid_t Entities::spawn( if (skeleton == nullptr) { throw std::runtime_error("skeleton "+def.skeletonName+" not found"); } - auto entity = registry.create(); entityid_t id; if (uid == 0) { id = nextID++; } else { id = uid; + if (auto found = get(uid)) { + std::stringstream ss; + ss << "UID #" << uid << " is already used by an entity "; + ss << found->getDef().name; + if (found->getID().destroyFlag) { + ss << " marked to destroy"; + } + throw std::runtime_error(ss.str()); + } } + auto entity = registry.create(); registry.emplace(entity, static_cast(id), def); const auto& tsf = registry.emplace( entity, position, glm::vec3(1.0f), glm::mat3(1.0f), glm::mat4(1.0f), true);