diff options
author | Aurélien Brooke <aurelien@bahiasoft.fr> | 2022-12-10 10:17:57 +0100 |
---|---|---|
committer | Aurélien Brooke <aurelien@bahiasoft.fr> | 2022-12-16 12:01:07 +0000 |
commit | c0af57b81ce8d4b3f851a2dbc94c1a1f5a7f9eb7 (patch) | |
tree | f7b80d4f01bb06b0d02f6bb50a322a724657fb18 | |
parent | a2978e5ee262ad9a7057e177c709e5efb72ee9e7 (diff) | |
download | qt3d-c0af57b81ce8d4b3f851a2dbc94c1a1f5a7f9eb7.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)
-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; } |