diff options
author | Tor Arne Vestbø <[email protected]> | 2024-02-08 18:31:33 +0100 |
---|---|---|
committer | Tor Arne Vestbø <[email protected]> | 2024-02-14 18:51:29 +0100 |
commit | 986f8b361ce9d6163f6ef691cad7b2955dcfe5cc (patch) | |
tree | e7fd4fc9dd83d8726a9f7731a8ca6d1c449fd43e | |
parent | 6fbbbef260cf71fee05d9e816c069964c6f0b92c (diff) |
QRhiWidget: Register cleanup callback also on first RHI init
The first time ensureRhi() is called we don't have an RHI yet, and will
adopt the top level's repaint manager's RHI. We need to register a
cleanup callback for this RHI, so that if it goes away, we will
reset our RHI pointer to null, just like when we switch from one top
level to another (and get a new potential RHI).
Without the reset, we would be working with a stale QRhi pointer,
which we in most cases updated via a call to ensureRhi(), that
picked up the new QRhi, but for good measure we should reset it
if we can.
Pick-to: 6.7
Change-Id: Iac6d8787b636675bbcb4358e8f0baad26187b0e2
Reviewed-by: Laszlo Agocs <[email protected]>
-rw-r--r-- | src/widgets/kernel/qrhiwidget.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/widgets/kernel/qrhiwidget.cpp b/src/widgets/kernel/qrhiwidget.cpp index 56a230fcb72..6c1a8194757 100644 --- a/src/widgets/kernel/qrhiwidget.cpp +++ b/src/widgets/kernel/qrhiwidget.cpp @@ -491,19 +491,21 @@ void QRhiWidgetPrivate::ensureRhi() } // NB the rhi member may be an invalid object, the pointer can be used, but no deref - if (currentRhi && rhi && rhi != currentRhi) { - // if previously we created our own but now get a QRhi from the - // top-level, then drop what we have and start using the top-level's - if (rhi == offscreenRenderer.rhi()) { - q->releaseResources(); // notify the user code about the early-release - releaseResources(); - offscreenRenderer.reset(); - } else { - // rhi resources created by us all belong to the old rhi, drop them; - // due to nulling out colorTexture this is also what ensures that - // initialize() is going to be called again eventually - resetRenderTargetObjects(); - resetColorBufferObjects(); + if (currentRhi && rhi != currentRhi) { + if (rhi) { + // if previously we created our own but now get a QRhi from the + // top-level, then drop what we have and start using the top-level's + if (rhi == offscreenRenderer.rhi()) { + q->releaseResources(); // notify the user code about the early-release + releaseResources(); + offscreenRenderer.reset(); + } else { + // rhi resources created by us all belong to the old rhi, drop them; + // due to nulling out colorTexture this is also what ensures that + // initialize() is going to be called again eventually + resetRenderTargetObjects(); + resetColorBufferObjects(); + } } // Normally the widget gets destroyed before the QRhi (which is managed by |