From 47ec5cf3400768c66ec4ef2fcc1350e898450e53 Mon Sep 17 00:00:00 2001 From: DragonAlex98 Date: Sun, 16 May 2021 16:43:11 +0200 Subject: [PATCH] ImageViewer: Stop animation timer when deleting/changing image Previously deleting an animated image wouldn't make the animation timer stop. This resulted in the animation still running in the ViewWidget. Moreover the timer wasn't stopped when loading different images, which led to high CPU usage when going from an animated image to a non-animated one. --- Userland/Applications/ImageViewer/ViewWidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp index 9ffbc3fe8c..59e6da99db 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.cpp +++ b/Userland/Applications/ImageViewer/ViewWidget.cpp @@ -31,6 +31,8 @@ ViewWidget::~ViewWidget() void ViewWidget::clear() { + m_timer->stop(); + m_decoded_image.clear(); m_bitmap = nullptr; if (on_image_change) on_image_change(m_bitmap); @@ -265,6 +267,8 @@ void ViewWidget::load_from_file(const String& path) m_timer->set_interval(first_frame.duration); m_timer->on_timeout = [this] { animate(); }; m_timer->start(); + } else { + m_timer->stop(); } m_path = path;