From 43c30e4f7b0f9b7f62707d3bfba98e18b4bdb212 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 27 Dec 2024 16:10:18 -0500 Subject: [PATCH] LibWeb/Animations: Keep a safe copy of associated animations The associated animations list might be modified on the time change event. This means that we can't safely iterate over the hashmap during this period. This fixes a crash in: - css/css-animations/CSSAnimation-effect.tentative.html --- Libraries/LibWeb/Animations/AnimationTimeline.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/Animations/AnimationTimeline.cpp b/Libraries/LibWeb/Animations/AnimationTimeline.cpp index 6761da42ec7..f906a5810b8 100644 --- a/Libraries/LibWeb/Animations/AnimationTimeline.cpp +++ b/Libraries/LibWeb/Animations/AnimationTimeline.cpp @@ -24,8 +24,12 @@ void AnimationTimeline::set_current_time(Optional value) } m_current_time = value; - for (auto& animation : m_associated_animations) + // The loop might modify the content of m_associated_animations, so let's iterate over a copy. + auto temporary_copy = GC::RootVector>(vm().heap()); + temporary_copy.extend(m_associated_animations.values()); + for (auto& animation : temporary_copy) { animation->notify_timeline_time_did_change(); + } } void AnimationTimeline::set_associated_document(GC::Ptr document)