Fix potential crash / memory leak when clearing layouts

This commit is contained in:
WarmUpTill 2022-03-18 22:12:50 +01:00 committed by WarmUpTill
parent 0a8f279e97
commit a6ca266dab
2 changed files with 4 additions and 6 deletions

View File

@ -43,7 +43,7 @@ std::string getSceneItemTransform(obs_scene_item *item);
void placeWidgets(std::string text, QBoxLayout *layout,
std::unordered_map<std::string, QWidget *> placeholders,
bool addStretch = true);
void deleteLayoutItem(QLayoutItem *item);
void deleteLayoutItemWidget(QLayoutItem *item);
void clearLayout(QLayout *layout, int afterIdx = 0);
void setLayoutVisible(QLayout *layout, bool visible);
QMetaObject::Connection PulseWidget(QWidget *widget, QColor startColor,

View File

@ -204,12 +204,13 @@ void placeWidgets(std::string text, QBoxLayout *layout,
}
}
void deleteLayoutItem(QLayoutItem *item)
void deleteLayoutItemWidget(QLayoutItem *item)
{
if (item) {
auto widget = item->widget();
if (widget) {
widget->setVisible(false);
widget->deleteLater();
}
delete item;
}
@ -223,10 +224,7 @@ void clearLayout(QLayout *layout, int afterIdx)
clearLayout(item->layout());
delete item->layout();
}
if (item->widget()) {
delete item->widget();
}
delete item;
deleteLayoutItemWidget(item);
}
}