From 2925d8dc54e1e60fa7ffcd2e40575c5d90e853e5 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 7 Nov 2024 14:53:04 -0300 Subject: [PATCH] Update creature.cpp --- src/creatures/creature.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index cacb7ba54f6..f3ad0e5d482 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -2004,13 +2004,15 @@ void Creature::sendAsyncTasks() { void Creature::safeCall(std::function &&action) const { if (g_dispatcher().context().isAsync()) { - g_dispatcher().addEvent([weak_self = std::weak_ptr(shared_from_this()), action = std::move(action)] { - if (weak_self.lock()) { - action(); + g_dispatcher().addEvent([weak_self = std::weak_ptr(static_self_cast()), action = std::move(action)] { + if (const auto self = weak_self.lock()) { + if (!self->isInternalRemoved) { + action(); + } } }, g_dispatcher().context().getName()); - } else { + } else if (!isInternalRemoved) { action(); } }