Skip to content

Commit

Permalink
improve: safecall (#3072)
Browse files Browse the repository at this point in the history
Added check if creature was removed.
  • Loading branch information
mehah authored Nov 7, 2024
1 parent 4ae6bdf commit e2e57f6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2004,13 +2004,15 @@ void Creature::sendAsyncTasks() {

void Creature::safeCall(std::function<void(void)> &&action) const {
if (g_dispatcher().context().isAsync()) {
g_dispatcher().addEvent([weak_self = std::weak_ptr<const SharedObject>(shared_from_this()), action = std::move(action)] {
if (weak_self.lock()) {
action();
g_dispatcher().addEvent([weak_self = std::weak_ptr<const Creature>(static_self_cast<Creature>()), action = std::move(action)] {
if (const auto self = weak_self.lock()) {
if (!self->isInternalRemoved) {
action();
}
}
},
g_dispatcher().context().getName());
} else {
} else if (!isInternalRemoved) {
action();
}
}

0 comments on commit e2e57f6

Please sign in to comment.