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> animation_did_finish = move(m_animation_did_finish); + (*animation_did_finish)(); + } } m_animation_current_step++; }