From eb7daf8eaa32456404faf203cf9c3f841a108cae Mon Sep 17 00:00:00 2001 From: gsemaj Date: Tue, 19 Jul 2022 09:14:38 -0700 Subject: [PATCH] Fix timed out buffs not calling onExpire --- src/Buffs.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Buffs.cpp b/src/Buffs.cpp index d790566..2c12434 100644 --- a/src/Buffs.cpp +++ b/src/Buffs.cpp @@ -12,8 +12,12 @@ void Buff::tick() { if(stack.durationTicks > 0) stack.durationTicks--; if(stack.durationTicks == 0) { + // erase() destroys the callbacks + // with the stack struct, so we need + // to copy it first. + BuffStack deadStack = stack; it = stacks.erase(it); - if(stack.onExpire) stack.onExpire(self, &stack); + if(deadStack.onExpire) deadStack.onExpire(self, &deadStack); } else it++; } }