Fix scene manager ref counting for shared scenes


An object can be referenced by more than one view, but we only track a
single scene manager per object. When the view owning the tracked
manager is destroyed the manager is deleted and our QPointer to it
auto-clears, yet the reference count is not decremented. A later
refSceneManager() call with a new manager then dereferenced the dead
manager while the count was already above one, crashing in
QQuick3DSceneManager::window().

Guard against this by only taking the "already set" branch when the
tracked manager is still alive. When it has been cleared we fall through
and re-adopt the new, valid manager instead. We deliberately do not
reset the reference count to zero, as other views may still reference
the object. The count may therefore over-count by the number of released
views, but the backend node is still released when the front-end object
is destroyed, as the destructor forces the final dereference. A proper
fix would track references per scene manager and a dedicated import
node.

Task-number: QTBUG-144962
Fixes: QTBUG-88320
Pick-to: 6.12 6.11
Change-Id: I83eff81a0ad1767f9bbd8d6cb824d01b8bad451d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
commita1ebb834352afdeda86f80fbf1015da957814708
parentbfeb4b1acd01d1f7e4f09eadc6c2ec1abf3b6fc6
authorChristian Strømme <christian.stromme@qt.io>
committerChristian Strømme <christian.stromme@qt.io>
commit timeTue, 4 Aug 2026 11:08:36 +0000