From 21fa0acd255e5e55dad0ffc1fc6553e739c3276c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Wed, 24 Apr 2019 15:15:12 +0300 Subject: Fix crash in editor when using qml stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The crash occurs due to stack overflow due to recursive subpresentation initialization in runtime codes. This happens because the qml subpresentation has the same id as the presentation filename, which is assigned to default initial id from the presentation filename. When the layer, which is using the qml subpresentation, is initialized in the runtime, it gets the uip presentation instead of the qml subpresentation. The same begins to happen recursively. Add the ability to change the initial presentation id from the surface viewer api, which is used to render the subpresentations in the editor so that it gets valid id instead of the id from filename. Task-number: QT3DS-3345 Change-Id: I45f3a8ce9b5dc030f120baa1a8aed6c284ea7e3c Reviewed-by: Jere Tuliniemi Reviewed-by: Tomi Korpipää Reviewed-by: Mahmoud Badri --- .../Studio/Render/StudioSubPresentationRenderer.cpp | 5 +++-- src/Runtime/Source/engine/Qt3DSTegraApplication.cpp | 5 +++++ src/Runtime/Source/engine/Qt3DSTegraApplication.h | 6 ++++++ src/Runtime/Source/runtime/Qt3DSApplication.cpp | 8 +++++++- src/Runtime/Source/runtime/Qt3DSApplication.h | 1 + src/Runtime/Source/viewer/Qt3DSViewerApp.cpp | 8 ++++++++ src/Runtime/Source/viewer/Qt3DSViewerApp.h | 2 ++ src/Viewer/studio3d/q3dssurfaceviewer.cpp | 17 +++++++++++++++++ src/Viewer/studio3d/q3dssurfaceviewer.h | 4 ++++ src/Viewer/studio3d/q3dssurfaceviewer_p.h | 1 + 10 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/Authoring/Studio/Render/StudioSubPresentationRenderer.cpp b/src/Authoring/Studio/Render/StudioSubPresentationRenderer.cpp index 160343e0..0af8758a 100644 --- a/src/Authoring/Studio/Render/StudioSubPresentationRenderer.cpp +++ b/src/Authoring/Studio/Render/StudioSubPresentationRenderer.cpp @@ -73,12 +73,13 @@ public: return QSize(); } - void initialize(const QString &presentation, const QString &path) + void initialize(const QString &id, const QString &presentation, const QString &path) { m_path = path; m_presentation = presentation; m_surfaceViewer.reset(new Q3DSSurfaceViewer); + m_surfaceViewer->setPresentationId(id); m_context.reset(new QT_PREPEND_NAMESPACE(QOpenGLContext)); m_surface.reset(new QOffscreenSurface); @@ -247,7 +248,7 @@ SOffscreenRenderFlags StudioSubpresentationRenderer::NeedsRender( void StudioSubpresentationRenderer::initialize() { - m_thread->initialize(m_presentation, m_path); + m_thread->initialize(m_id, m_presentation, m_path); m_thread->start(); m_thread->m_semaphore.acquire(); if (m_callback) diff --git a/src/Runtime/Source/engine/Qt3DSTegraApplication.cpp b/src/Runtime/Source/engine/Qt3DSTegraApplication.cpp index 663fe836..b85cbd32 100644 --- a/src/Runtime/Source/engine/Qt3DSTegraApplication.cpp +++ b/src/Runtime/Source/engine/Qt3DSTegraApplication.cpp @@ -205,6 +205,11 @@ public: void SetDataInputValue(const QString &name, const QVariant &value, Q3DSDataInput::ValueRole property) override; + void setPresentationId(const QString &id) override + { + m_Application->setPresentationId(id); + } + QList dataInputs() const override; float dataInputMax(const QString &name) const override; float dataInputMin(const QString &name) const override; diff --git a/src/Runtime/Source/engine/Qt3DSTegraApplication.h b/src/Runtime/Source/engine/Qt3DSTegraApplication.h index 75b6058b..d68e9efa 100644 --- a/src/Runtime/Source/engine/Qt3DSTegraApplication.h +++ b/src/Runtime/Source/engine/Qt3DSTegraApplication.h @@ -174,6 +174,8 @@ public: // loading virtual INT32 GetFrameCount() = 0; virtual void showOnScreenStats(bool) = 0; + virtual void setPresentationId(const QString &id) = 0; + public: // Input engine access virtual CInputEngine *GetInputEngine() = 0; // Only valid after InitializeGraphics @@ -334,6 +336,10 @@ public: { return m_NDDView; } + void setPresentationId(const QString &id) + { + m_NDDView->setPresentationId(id); + } }; } // namespace Q3DStudio diff --git a/src/Runtime/Source/runtime/Qt3DSApplication.cpp b/src/Runtime/Source/runtime/Qt3DSApplication.cpp index 6e7a2eb8..ac7ee76e 100644 --- a/src/Runtime/Source/runtime/Qt3DSApplication.cpp +++ b/src/Runtime/Source/runtime/Qt3DSApplication.cpp @@ -565,6 +565,11 @@ struct SApp : public IApplication } } + void setPresentationId(const QString &id) override + { + m_InitialPresentationId.assign(qPrintable(id)); + } + void setAssetVisitor(qt3ds::Qt3DSAssetVisitor *v) override { m_visitor = v; @@ -1348,7 +1353,8 @@ struct SApp : public IApplication #if !defined(_LINUXPLATFORM) && !defined(_INTEGRITYPLATFORM) ConnectDebugger(); #endif - m_InitialPresentationId.assign(filename.c_str()); + if (m_InitialPresentationId.empty()) + m_InitialPresentationId.assign(filename.c_str()); eastl::string relativePath = "./"; relativePath.append(filename); relativePath.append("."); diff --git a/src/Runtime/Source/runtime/Qt3DSApplication.h b/src/Runtime/Source/runtime/Qt3DSApplication.h index f0ccb175..d4dba733 100644 --- a/src/Runtime/Source/runtime/Qt3DSApplication.h +++ b/src/Runtime/Source/runtime/Qt3DSApplication.h @@ -241,6 +241,7 @@ public: virtual float dataInputMin(const QString &name) const = 0; + virtual void setPresentationId(const QString &id) = 0; }; } } diff --git a/src/Runtime/Source/viewer/Qt3DSViewerApp.cpp b/src/Runtime/Source/viewer/Qt3DSViewerApp.cpp index 853a58ac..2b5c0af1 100644 --- a/src/Runtime/Source/viewer/Qt3DSViewerApp.cpp +++ b/src/Runtime/Source/viewer/Qt3DSViewerApp.cpp @@ -754,6 +754,14 @@ void Q3DSViewerApp::SetDataInputValue( m_Impl.m_tegraApp->SetDataInputValue(name, value, valueRole); } +void Q3DSViewerApp::setPresentationId(const QString &id) +{ + if (!m_Impl.m_tegraApp) + return; + + m_Impl.m_tegraApp->setPresentationId(id); +} + QList Q3DSViewerApp::dataInputs() const { if (!m_Impl.m_tegraApp) diff --git a/src/Runtime/Source/viewer/Qt3DSViewerApp.h b/src/Runtime/Source/viewer/Qt3DSViewerApp.h index 4cc15def..df034653 100644 --- a/src/Runtime/Source/viewer/Qt3DSViewerApp.h +++ b/src/Runtime/Source/viewer/Qt3DSViewerApp.h @@ -358,6 +358,8 @@ public: QString error(); + void setPresentationId(const QString &id); + private: /* * @brief parse command line arguments this fills in our diff --git a/src/Viewer/studio3d/q3dssurfaceviewer.cpp b/src/Viewer/studio3d/q3dssurfaceviewer.cpp index f477723b..c64ecbfc 100644 --- a/src/Viewer/studio3d/q3dssurfaceviewer.cpp +++ b/src/Viewer/studio3d/q3dssurfaceviewer.cpp @@ -121,6 +121,11 @@ bool Q3DSSurfaceViewer::isRunning() const return d_ptr->m_viewerApp != nullptr; } +QString Q3DSSurfaceViewer::presentationId() const +{ + return d_ptr->m_id; +} + int Q3DSSurfaceViewer::fboId() const { return d_ptr->m_fboId; @@ -146,6 +151,16 @@ Q3DSPresentation *Q3DSSurfaceViewer::presentation() const return d_ptr->m_presentation; } +void Q3DSSurfaceViewer::setPresentationId(const QString &id) +{ + if (d_ptr->m_id != id) { + d_ptr->m_id = id; + Q_EMIT presentationIdChanged(id); + if (d_ptr->m_viewerApp) + d_ptr->m_viewerApp->setPresentationId(id); + } +} + Q3DSSurfaceViewerPrivate::Q3DSSurfaceViewerPrivate(Q3DSSurfaceViewer *q) : QObject(q) , q_ptr(q) @@ -159,6 +174,7 @@ Q3DSSurfaceViewerPrivate::Q3DSSurfaceViewerPrivate(Q3DSSurfaceViewer *q) , m_autoSize(true) , m_settings(new Q3DSViewerSettings(this)) , m_presentation(new Q3DSPresentation(this)) + , m_id(QStringLiteral("initial")) { connect(m_presentation, &Q3DSPresentation::sourceChanged, this, &Q3DSSurfaceViewerPrivate::reset); @@ -362,6 +378,7 @@ bool Q3DSSurfaceViewerPrivate::initializeRuntime() return false; } + m_viewerApp->setPresentationId(m_id); m_settings->d_ptr->setViewerApp(m_viewerApp); m_presentation->d_ptr->setViewerApp(m_viewerApp); diff --git a/src/Viewer/studio3d/q3dssurfaceviewer.h b/src/Viewer/studio3d/q3dssurfaceviewer.h index 80c6692d..fc99ccaf 100644 --- a/src/Viewer/studio3d/q3dssurfaceviewer.h +++ b/src/Viewer/studio3d/q3dssurfaceviewer.h @@ -53,6 +53,7 @@ class Q_STUDIO3D_EXPORT Q3DSSurfaceViewer : public QObject Q_PROPERTY(bool autoSize READ autoSize WRITE setAutoSize NOTIFY autoSizeChanged) Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged) Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged) + Q_PROPERTY(QString presentationId READ presentationId WRITE setPresentationId NOTIFY presentationIdChanged) public: explicit Q3DSSurfaceViewer(QObject *parent = nullptr); @@ -67,6 +68,7 @@ public: bool autoSize() const; int updateInterval() const; bool isRunning() const; + QString presentationId() const; int fboId() const; QSurface *surface() const; @@ -82,6 +84,7 @@ public Q_SLOTS: void update(); void shutdown(); void reset(); + void setPresentationId(const QString &id); Q_SIGNALS: void sizeChanged(const QSize &size); @@ -89,6 +92,7 @@ Q_SIGNALS: void updateIntervalChanged(bool autoUpdate); void runningChanged(bool initialized); void frameUpdated(); + void presentationIdChanged(const QString &id); private: Q_DISABLE_COPY(Q3DSSurfaceViewer) diff --git a/src/Viewer/studio3d/q3dssurfaceviewer_p.h b/src/Viewer/studio3d/q3dssurfaceviewer_p.h index f82e4ba3..a668513e 100644 --- a/src/Viewer/studio3d/q3dssurfaceviewer_p.h +++ b/src/Viewer/studio3d/q3dssurfaceviewer_p.h @@ -94,6 +94,7 @@ private: bool m_autoSize; Q3DSViewerSettings *m_settings; Q3DSPresentation *m_presentation; + QString m_id; }; QT_END_NAMESPACE -- cgit v1.2.3