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 <laszlo.agocs@qt.io>
This commit is contained in:
parent
6fbbbef260
commit
986f8b361c
@ -491,19 +491,21 @@ void QRhiWidgetPrivate::ensureRhi()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NB the rhi member may be an invalid object, the pointer can be used, but no deref
|
// NB the rhi member may be an invalid object, the pointer can be used, but no deref
|
||||||
if (currentRhi && rhi && rhi != currentRhi) {
|
if (currentRhi && rhi != currentRhi) {
|
||||||
// if previously we created our own but now get a QRhi from the
|
if (rhi) {
|
||||||
// top-level, then drop what we have and start using the top-level's
|
// if previously we created our own but now get a QRhi from the
|
||||||
if (rhi == offscreenRenderer.rhi()) {
|
// top-level, then drop what we have and start using the top-level's
|
||||||
q->releaseResources(); // notify the user code about the early-release
|
if (rhi == offscreenRenderer.rhi()) {
|
||||||
releaseResources();
|
q->releaseResources(); // notify the user code about the early-release
|
||||||
offscreenRenderer.reset();
|
releaseResources();
|
||||||
} else {
|
offscreenRenderer.reset();
|
||||||
// rhi resources created by us all belong to the old rhi, drop them;
|
} else {
|
||||||
// due to nulling out colorTexture this is also what ensures that
|
// rhi resources created by us all belong to the old rhi, drop them;
|
||||||
// initialize() is going to be called again eventually
|
// due to nulling out colorTexture this is also what ensures that
|
||||||
resetRenderTargetObjects();
|
// initialize() is going to be called again eventually
|
||||||
resetColorBufferObjects();
|
resetRenderTargetObjects();
|
||||||
|
resetColorBufferObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normally the widget gets destroyed before the QRhi (which is managed by
|
// Normally the widget gets destroyed before the QRhi (which is managed by
|
||||||
|
Loading…
x
Reference in New Issue
Block a user