From d9d387ad47966d1cdebe5f7a8e0c1acd71a160e7 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:31:11 +0200 Subject: [PATCH] Fix crash when deleting cached macro widgets --- lib/macro/macro-segment-list.cpp | 13 ++++++++----- lib/macro/macro-segment-list.hpp | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/macro/macro-segment-list.cpp b/lib/macro/macro-segment-list.cpp index 99d16ead..03320590 100644 --- a/lib/macro/macro-segment-list.cpp +++ b/lib/macro/macro-segment-list.cpp @@ -56,9 +56,7 @@ MacroSegmentList::~MacroSegmentList() _autoScrollThread.join(); } - for (const auto &[_, widgets] : _widgetCache) { - clearWidgetVector(widgets); - } + ClearWidgetCache(); } static bool posIsInScrollbar(const QScrollBar *scrollbar, const QPoint &pos) @@ -146,7 +144,6 @@ void MacroSegmentList::SetCachingEnabled(bool enable) void MacroSegmentList::CacheCurrentWidgetsFor(const Macro *macro) { if (!_useCache) { - _widgetCache.clear(); return; } @@ -168,7 +165,6 @@ void MacroSegmentList::CacheCurrentWidgetsFor(const Macro *macro) bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro) { if (!_useCache) { - _widgetCache.clear(); return false; } @@ -340,6 +336,13 @@ void MacroSegmentList::HideLastDropLine() _dropLineIdx = -1; } +void MacroSegmentList::ClearWidgetCache() +{ + for (const auto &[_, widgets] : _widgetCache) { + clearWidgetVector(widgets); + } +} + static bool isInUpperHalfOf(const QPoint &pos, const QRect &rect) { return QRect(rect.topLeft(), diff --git a/lib/macro/macro-segment-list.hpp b/lib/macro/macro-segment-list.hpp index f14922fc..95988c71 100644 --- a/lib/macro/macro-segment-list.hpp +++ b/lib/macro/macro-segment-list.hpp @@ -61,6 +61,7 @@ private: bool IsInListArea(const QPoint &) const; QRect GetContentItemRectWithPadding(int idx) const; void HideLastDropLine(); + void ClearWidgetCache(); int _dragPosition = -1; int _dropLineIdx = -1;