diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-04 10:50:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-04 19:32:25 +0200 |
commit | fab9b2f068cb324e38b1f22e95ffa424d93da443 (patch) | |
tree | bb20fbe3cbbc4e5487abeb36f5fd196e4e0db582 /Userland/Games | |
parent | fdaec58f594b6fac7a64913ca454337f102fd41b (diff) | |
download | serenity-fab9b2f068cb324e38b1f22e95ffa424d93da443.zip |
Hearts: Don't destroy the animation handler while running it
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Hearts/Game.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index 4b10ff16fe..88b4b6f34b 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -270,8 +270,12 @@ void Game::timer_event(Core::TimerEvent&) if (m_animation_current_step >= m_animation_steps) { stop_timer(); m_animation_playing = false; - if (m_animation_did_finish) - (*m_animation_did_finish)(); + if (m_animation_did_finish) { + // The did_finish handler might end up destroying/replacing the handler + // so we have to save it first. + OwnPtr<Function<void()>> animation_did_finish = move(m_animation_did_finish); + (*animation_did_finish)(); + } } m_animation_current_step++; } |