Keep the window attachment alive for the window's lifetime
QQuick3DWindowAttachment owns the per-window QSSGRenderRoot. Nodes refer
back to that root through rootNodeRef, and the value is refreshed for
every node on each sync. Imported scenes are owned by the QML tree, not
by a view, so they can outlive any individual view. When the last scene
manager in a window went away, evaluateEol() deleted the attachment and
with it the render root, leaving the imported nodes' rootNodeRef
dangling. The next view to import the same scene then read the freed
root in setImportScene(), causing a use-after-free.
Keep the attachment, and the root it owns, alive for as long as the
window is, even when no scene managers remain; the explicit end-of-life
deletion now only happens once there are neither scene managers nor a
window left. To make sure the attachment is still torn down when the
window goes away, connect QQuickWindow::destroyed directly to
evaluateEol() rather than to a deferred deleteLater(), which would be
posted too late and dropped during window teardown. This keeps
rootNodeRef valid across view create and destroy cycles within a window
without having to clear it on every node. reindex() already rebuilds the
global node data from the live tree on every change, so reusing the root
introduces no stale state.
Pick-to: 6.12 6.11
Change-Id: Ie722be5ed001cff4c833e05911cba7f8a9629026
Reviewed-by: Andy Nichols <andy.nichols@qt.io>