From 9908f37e55f2bc980d8c788290ee40e8ff4cb9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Wed, 5 Jun 2019 09:20:47 +0300 Subject: Fix simplewindow example The surface viewer tries to initialize the runtime before we have valid surface and context. Delay the initialization until they have been created. Task-number: QT3DS-3619 Change-Id: Ia427ce3af4e568be1b317bf798777c7eb3f773fc Reviewed-by: Miikka Heikkinen --- .../src/api/studio3d/q3dssurfaceviewer.cpp | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp index 401c461d..d6074837 100644 --- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp +++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp @@ -475,6 +475,7 @@ bool Q3DSSurfaceViewerPrivate::initialize(QSurface *surface, QOpenGLContext *con connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &Q3DSSurfaceViewerPrivate::destroy); bool success = initializeRuntime(); + resetUpdateTimer(); if (success) Q_EMIT q_ptr->runningChanged(true); @@ -512,10 +513,17 @@ void Q3DSSurfaceViewerPrivate::destroy() */ void Q3DSSurfaceViewerPrivate::update() { - if (m_viewerApp && m_viewerApp->IsInitialised()) { + if (m_viewerApp) { if (m_surface->surfaceClass() != QSurface::Window || static_cast(m_surface)->isExposed()) { - m_context->makeCurrent(m_surface); + if (!m_context->makeCurrent(m_surface)) { + qWarning () << "Q3DSSurfaceViewer: Unable to make context current"; + return; + } + + if (!m_viewerApp->IsInitialised() && !initializeRuntime()) + return; + if (m_autoSize) setSize(m_surface->size()); m_viewerApp->Render(); @@ -596,6 +604,7 @@ void Q3DSSurfaceViewerPrivate::reset() if (m_viewerApp) { releaseRuntime(); initializeRuntime(); + resetUpdateTimer(); } } @@ -616,16 +625,19 @@ void Q3DSSurfaceViewerPrivate::setError(const QString &error) */ bool Q3DSSurfaceViewerPrivate::initializeRuntime() { - Q_ASSERT(!m_viewerApp); - - m_context->makeCurrent(m_surface); + if (!m_viewerApp) { + m_viewerApp = &Q3DSViewerApp::Create(m_context, new Qt3DSAudioPlayerImpl(), &m_startupTimer); + connect(m_viewerApp, &Q3DSViewerApp::SigPresentationReady, + this->q_ptr, &Q3DSSurfaceViewer::presentationReady); + connect(m_viewerApp, &Q3DSViewerApp::SigPresentationLoaded, + this->q_ptr, &Q3DSSurfaceViewer::presentationLoaded); + Q_ASSERT(m_viewerApp); + } + if (!m_context->makeCurrent(m_surface)) { + qWarning () << "Q3DSSurfaceViewer: Unable to make context current"; + return false; + } - m_viewerApp = &Q3DSViewerApp::Create(m_context, new Qt3DSAudioPlayerImpl(), &m_startupTimer); - connect(m_viewerApp, &Q3DSViewerApp::SigPresentationReady, - this->q_ptr, &Q3DSSurfaceViewer::presentationReady); - connect(m_viewerApp, &Q3DSViewerApp::SigPresentationLoaded, - this->q_ptr, &Q3DSSurfaceViewer::presentationLoaded); - Q_ASSERT(m_viewerApp); const QString localSource = Q3DSUtils::urlToLocalFileOrQrc(m_presentation->source()); @@ -651,9 +663,6 @@ bool Q3DSSurfaceViewerPrivate::initializeRuntime() m_viewerApp->setPresentationId(m_id); m_settings->d_ptr->setViewerApp(m_viewerApp); m_presentation->d_ptr->setViewerApp(m_viewerApp); - - resetUpdateTimer(); - return true; } -- cgit v1.2.3