From ade6f18f6f1da8e801ba708b0a0f3c452f035a5e Mon Sep 17 00:00:00 2001 From: Amyr Ahmady Date: Sun, 24 Sep 2023 04:31:15 +0330 Subject: [PATCH] add temporary code to objects component ontick --- Server/Components/Objects/objects_impl.hpp | 9 ++++-- Server/Components/Objects/objects_main.cpp | 36 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Server/Components/Objects/objects_impl.hpp b/Server/Components/Objects/objects_impl.hpp index 7def53c4c..3daf0d638 100644 --- a/Server/Components/Objects/objects_impl.hpp +++ b/Server/Components/Objects/objects_impl.hpp @@ -381,11 +381,13 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler, void release(int index) override { - auto ptr = storage.get(index); - if (ptr) + auto obj = storage.get(index); + if (obj) { - static_cast(ptr)->destream(); + obj->destream(); storage.release(index, false); + processedObjects.erase(obj); + attachedToPlayer.erase(obj); } } @@ -597,6 +599,7 @@ class PlayerObjectData final : public IPlayerObjectData obj->destream(); storage.release(index, false); attachedToPlayer_.erase(obj); + component_.getPlayerProcessedObjects().erase(obj); } } diff --git a/Server/Components/Objects/objects_main.cpp b/Server/Components/Objects/objects_main.cpp index 92e0ffa8b..92e340cab 100644 --- a/Server/Components/Objects/objects_main.cpp +++ b/Server/Components/Objects/objects_main.cpp @@ -10,6 +10,42 @@ void ObjectComponent::onTick(Microseconds elapsed, TimePoint now) { + { + std::vector debugRemoveObjs; + for (auto it = processedObjects.begin(); it != processedObjects.end();) + { + Object* obj = *(it++); + if (!obj) + { + core->logLn(LogLevel::Error, "ObjectComponent::onTick: processedObjects loop nullptr!"); + debugRemoveObjs.push_back(obj); + continue; + } + + bool found = false; + for (IObject* obj_interface : storage) + { + Object* pool_obj = static_cast(obj_interface); + if(pool_obj == obj) + { + found = true; + break; + } + } + + if(!found) + { + core->logLn(LogLevel::Error, "ObjectComponent::onTick: processedObjects loop obj not found in pool!"); + debugRemoveObjs.push_back(obj); + continue; + } + } + + for (Object* obj : debugRemoveObjs) + { + processedObjects.erase(obj); + } +} for (auto it = processedObjects.begin(); it != processedObjects.end();) { Object* obj = *(it++);