From 31f0e3aa00f80ba4a0f4a06cf2ca4121b86f41b7 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 30 May 2014 13:53:25 +0200 Subject: Fix QQuickWidget cleanup and invalidation sequence Make sure the context/surface are still alive and current while destroying the render control. Task-number: QTBUG-39034 Change-Id: I6ff0069985a9121a63025bfb165493b3f003391d Reviewed-by: Gunnar Sletta --- src/quickwidgets/qquickwidget.cpp | 40 +++++++++++++++++++++++---------------- src/quickwidgets/qquickwidget_p.h | 1 + 2 files changed, 25 insertions(+), 16 deletions(-) (limited to 'src/quickwidgets') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index b25912a1de..aea21af3a0 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -117,9 +117,23 @@ void QQuickWidgetPrivate::init(QQmlEngine* e) QObject::connect(renderControl, SIGNAL(sceneChanged()), q, SLOT(triggerUpdate())); } -void QQuickWidgetPrivate::handleWindowChange() +void QQuickWidgetPrivate::stopRenderControl() { + if (!context) // this is not an error, could be called before creating the context, or multiple times + return; + + bool success = context->makeCurrent(offscreenSurface); + if (!success) { + qWarning("QQuickWidget::stopRenderControl could not make context current"); + return; + } + renderControl->stop(); +} + +void QQuickWidgetPrivate::handleWindowChange() +{ + stopRenderControl(); destroyContext(); } @@ -143,10 +157,17 @@ QQuickWidgetPrivate::~QQuickWidgetPrivate() { if (QQmlDebugService::isDebuggingEnabled()) QQmlInspectorService::instance()->removeView(q_func()); - delete offscreenSurface; + + stopRenderControl(); + + // context and offscreenSurface are current at this stage, if the context was created. + Q_ASSERT(!context || (QOpenGLContext::currentContext() == context && context->surface() == offscreenSurface)); delete offscreenWindow; delete renderControl; delete fbo; + + delete offscreenSurface; + destroyContext(); } void QQuickWidgetPrivate::createOffscreenSurface() @@ -628,9 +649,6 @@ void QQuickWidgetPrivate::createContext() void QQuickWidgetPrivate::destroyContext() { - if (!context) - return; - renderControl->invalidate(); delete context; context = 0; } @@ -906,17 +924,7 @@ void QQuickWidget::showEvent(QShowEvent *) void QQuickWidget::hideEvent(QHideEvent *) { Q_D(QQuickWidget); - - if (!d->context) { - qWarning("QQuickWidget::hideEvent with no context"); - return; - } - bool success = d->context->makeCurrent(d->offscreenSurface); - if (!success) { - qWarning("QQuickWidget::hideEvent could not make context current"); - return; - } - d->renderControl->stop(); + d->stopRenderControl(); } /*! \reimp */ diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h index 5cf2bfbf1d..8efe32b3ce 100644 --- a/src/quickwidgets/qquickwidget_p.h +++ b/src/quickwidgets/qquickwidget_p.h @@ -93,6 +93,7 @@ public: void init(QQmlEngine* e = 0); void handleWindowChange(); + void stopRenderControl(); QSize rootObjectSize() const; -- cgit v1.2.3