summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <[email protected]>2024-02-08 17:55:58 +0100
committerTor Arne Vestbø <[email protected]>2024-02-14 18:51:29 +0100
commit6fbbbef260cf71fee05d9e816c069964c6f0b92c (patch)
tree71aec09fabb9cb573588d498bb685ca5f61f7275
parent1ca7368d5931ecab14ea928955cecb5bf90c2b7d (diff)
QRhiWidget: Tear down resources before window has changed
We were handling QEvent::WindowChangeInternal, but based on what the code is doing, what the comments say, and what QQuickWidget does, the right event should be WindowAboutToChangeInternal. This fixes a crash when reparenting a QRhiWidget into another widget, where we could call removeCleanupCallback() on an RHI that was already gone. The fact that we have a stale RHI pointer at WindowChangeInternal time is still problematic, and caused by our call to addCleanupCallback not happening as it should for the first call to ensureRhi(), but this will be fixed in a follow up. Pick-to: 6.7 Change-Id: I054120e97a24a1f74af44b2d251470792f03f7f3 Reviewed-by: Laszlo Agocs <[email protected]>
-rw-r--r--src/widgets/kernel/qrhiwidget.cpp2
-rw-r--r--tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/widgets/kernel/qrhiwidget.cpp b/src/widgets/kernel/qrhiwidget.cpp
index 0382caecc7e..56a230fcb72 100644
--- a/src/widgets/kernel/qrhiwidget.cpp
+++ b/src/widgets/kernel/qrhiwidget.cpp
@@ -277,7 +277,7 @@ bool QRhiWidget::event(QEvent *e)
{
Q_D(QRhiWidget);
switch (e->type()) {
- case QEvent::WindowChangeInternal:
+ case QEvent::WindowAboutToChangeInternal:
// The QRhi will almost certainly change, prevent texture() from
// returning the existing QRhiTexture in the meantime.
d->textureInvalid = true;
diff --git a/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp b/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp
index 988f736e4e6..9f56c776377 100644
--- a/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp
+++ b/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp
@@ -635,12 +635,19 @@ void tst_QRhiWidget::reparent()
QWidget *windowOne = new QWidget;
windowOne->resize(1280, 720);
- SimpleRhiWidget *rhiWidget = new SimpleRhiWidget(1, windowOne);
+ SimpleRhiWidget *rhiWidget = new SimpleRhiWidget(1);
rhiWidget->setApi(api);
rhiWidget->resize(800, 600);
QSignalSpy frameSpy(rhiWidget, &QRhiWidget::frameSubmitted);
QSignalSpy errorSpy(rhiWidget, &QRhiWidget::renderFailed);
+ rhiWidget->show();
+ QVERIFY(QTest::qWaitForWindowExposed(rhiWidget));
+ QTRY_VERIFY(frameSpy.count() > 0);
+ QCOMPARE(errorSpy.count(), 0);
+
+ frameSpy.clear();
+ rhiWidget->setParent(windowOne);
windowOne->show();
QVERIFY(QTest::qWaitForWindowExposed(windowOne));
QTRY_VERIFY(frameSpy.count() > 0);