diff options
author | Aurélien Brooke <aurelien@bahiasoft.fr> | 2022-12-10 10:17:57 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-12-15 10:01:16 +0000 |
commit | c1a833906d5458468c6157263aaf392fa0e67396 (patch) | |
tree | 0a7d52119d548c3beb13856ec13d29fde9370e50 | |
parent | f9657e06d0320b0823237d627b468491b7127bf0 (diff) | |
download | qt3d-c1a833906d5458468c6157263aaf392fa0e67396.tar.gz |
Scene3DItem: fix assert when changing window
In Scene3DItem::updatePaintNode(), in the Render thread, we try to set
the parent of the aspect engine being deleted to nullptr. This was
triggering an assert in QCoreApplication::sendEvent(), since the aspect
engine lives in a different thread, the Main thread.
Don't trigger this assert by avoiding to send ChildAdded/ChildRemoved
events when reparenting the aspect manager, thanks to the
QQml_setParent_noEvent utility.
Change-Id: Ic816701ee65654f7b18b4998c54feb4840af0a14
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
(cherry picked from commit 63a9c3e314364765437f641454637611c2479672)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick3d/imports/scene3d/scene3ditem.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/quick3d/imports/scene3d/scene3ditem.cpp b/src/quick3d/imports/scene3d/scene3ditem.cpp index eb960a8dc..d1f1cea72 100644 --- a/src/quick3d/imports/scene3d/scene3ditem.cpp +++ b/src/quick3d/imports/scene3d/scene3ditem.cpp @@ -26,6 +26,7 @@ #include <QtGui/qguiapplication.h> #include <QtGui/qoffscreensurface.h> +#include <QtQml/private/qqmlglobal_p.h> #include <QtQuick/qquickwindow.h> #include <QtQuick/qquickrendercontrol.h> @@ -742,9 +743,13 @@ QSGNode *Scene3DItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNode qCWarning(Scene3D) << "Renderer for Scene3DItem has requested a reset due to the item " "moving to another window"; QObject::disconnect(m_windowConnection); + // We are in the Render thread, and the m_aspectEngineDestroyer lives in the Main + // thread, so we must avoid sending ChildRemoved or ChildAdded events to it with a + // QObject::setParent(). QCoreApplication::sendEvent() would fail with "Cannot + // send events to objects owned by a different thread." + QQml_setParent_noEvent(m_aspectEngine, nullptr); // Note: AspectEngine can only be deleted once we have set the root // entity on the new instance - m_aspectEngine->setParent(nullptr); m_aspectToDelete = m_aspectEngine; m_aspectEngine = nullptr; } |