diff options
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
| -rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index fb3c8554be..5b3e4394ce 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -655,6 +655,9 @@ QQuickWidget::~QQuickWidget() delete d->root; d->root = nullptr; + if (d->rhi) + d->rhi->removeCleanupCallback(this); + // NB! resetting graphics resources must be done from this destructor, // *not* from the private class' destructor. This is due to how destruction // works and due to the QWidget dtor (for toplevels) destroying the repaint @@ -1021,8 +1024,19 @@ void QQuickWidgetPrivate::initializeWithRhi() if (rhi) return; - if (QWidgetRepaintManager *repaintManager = tlwd->maybeRepaintManager()) + if (QWidgetRepaintManager *repaintManager = tlwd->maybeRepaintManager()) { rhi = repaintManager->rhi(); + if (rhi) { + // We don't own the RHI, so make sure we clean up if it goes away + rhi->addCleanupCallback(q, [this](QRhi *rhi) { + if (this->rhi == rhi) { + invalidateRenderControl(); + deviceLost = true; + this->rhi = nullptr; + } + }); + } + } if (!rhi) { // The widget (and its parent chain, if any) may not be shown at @@ -1675,6 +1689,8 @@ bool QQuickWidget::event(QEvent *e) } case QEvent::WindowAboutToChangeInternal: + if (d->rhi) + d->rhi->removeCleanupCallback(this); d->invalidateRenderControl(); d->deviceLost = true; d->rhi = nullptr; |
