Fix crash when deleting macro

This commit is contained in:
WarmUpTill
2025-05-29 21:48:05 +02:00
committed by WarmUpTill
parent c567e6ef7f
commit 30422aecf3
5 changed files with 80 additions and 45 deletions

View File

@@ -42,6 +42,13 @@ MacroSegmentList::MacroSegmentList(QWidget *parent)
[this]() { SetupVisibleMacroSegmentWidgets(); });
}
static void clearWidgetVector(const std::vector<QWidget *> &widgets)
{
for (auto widget : widgets) {
widget->deleteLater();
}
};
MacroSegmentList::~MacroSegmentList()
{
if (_autoScrollThread.joinable()) {
@@ -49,13 +56,6 @@ MacroSegmentList::~MacroSegmentList()
_autoScrollThread.join();
}
const auto clearWidgetVector =
[](const std::vector<QWidget *> &widgets) {
for (auto widget : widgets) {
widget->deleteLater();
}
};
for (const auto &[_, widgets] : _widgetCache) {
clearWidgetVector(widgets);
}
@@ -185,6 +185,16 @@ bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro)
return true;
}
void MacroSegmentList::ClearWidgetsFromCacheFor(const Macro *macro)
{
auto it = _widgetCache.find(macro);
if (it == _widgetCache.end()) {
return;
}
clearWidgetVector(it->second);
_widgetCache.erase(it);
}
void MacroSegmentList::Highlight(int idx, QColor color)
{
auto item = _contentLayout->itemAt(idx);