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++);