Fix crashes related to PulseWidget()

* Fix crash if widget was deleted during animation
* Fix crash if multiple animations were started at the same time
This commit is contained in:
WarmUpTill 2022-02-16 21:48:07 +01:00 committed by WarmUpTill
parent 0b2e725471
commit bdd489aea5

View File

@ -892,7 +892,16 @@ QMetaObject::Connection PulseWidget(QWidget *widget, QColor startColor,
paAnimation->setDuration(1000);
QMetaObject::Connection con;
if (!once) {
if (once) {
auto widgetPtr = widget;
con = QWidget::connect(
paAnimation, &QPropertyAnimation::finished,
[widgetPtr]() {
if (widgetPtr) {
widgetPtr->setGraphicsEffect(nullptr);
}
});
} else {
con = QWidget::connect(
paAnimation, &QPropertyAnimation::finished,
[paAnimation]() {
@ -900,10 +909,6 @@ QMetaObject::Connection PulseWidget(QWidget *widget, QColor startColor,
paAnimation->start();
});
});
} else {
con = QWidget::connect(
paAnimation, &QPropertyAnimation::finished,
[widget]() { widget->setGraphicsEffect(nullptr); });
}
paAnimation->start();