1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:57:34 +00:00

WindowServer: Fix animation crash

If an Animation's on_stop handler cleared itself inside the on_stop
event handler, it would remove itself from the animation map that was
still being iterated, leading to a crash.

To solve this, we'll iterate over the animations using the
remove_all_matching function, which enables us to delete it by simply
returning true when the animation finished. In the event that the
Animation is kept alive elsewhere and the on_stop event clears its own
reference, we need to temporarily bump the reference count. Another
advantage is that we only need to bump the reference count when an
animation is finished, whereas before this we bumped it
unconditionally.
This commit is contained in:
Tom 2022-03-16 20:22:13 -06:00 committed by Andreas Kling
parent 56046d3f9b
commit 9f59d7d9a0
3 changed files with 31 additions and 8 deletions

View file

@ -28,11 +28,12 @@ public:
void start();
void stop();
void was_removed(Badge<Compositor>);
void set_duration(int duration_in_ms);
int duration() const { return m_duration; }
void update(Badge<Compositor>, Gfx::Painter&, Screen&, Gfx::DisjointRectSet& flush_rects);
bool update(Badge<Compositor>, Gfx::Painter&, Screen&, Gfx::DisjointRectSet& flush_rects);
Function<void(float progress, Gfx::Painter&, Screen&, Gfx::DisjointRectSet& flush_rects)> on_update;
Function<void()> on_stop;
@ -43,6 +44,7 @@ private:
Core::ElapsedTimer m_timer;
int m_duration { 0 };
bool m_running { false };
bool m_was_removed { false };
};
}