From a29337be6ea54557498202ee99df1325238ea19a Mon Sep 17 00:00:00 2001
From: Laszlo Agocs <laszlo.agocs@digia.com>
Date: Mon, 17 Nov 2014 16:11:22 +0100
Subject: [PATCH] Do not send deferred deletes from
 QQuickRenderControl::invalidate()

Leave it up to the clients of QQuickRenderControl to do this, if they
want it. It is usually not necessary.

In the single-threaded widget world forcing deferred deletes to execute
on every invalidate(), so for example from the hide event handler of
QQuickWidget, is dangerous because widget apps tend to deleteLater()
all sorts of widgets which can then be destroyed at unexpected times.

From windowDestroyed() we continue to send the deferred deletes, just
like all the render loops do.

Task-number: QTBUG-42618
Task-number: QTBUG-40435
Change-Id: I8189124e2e7675361ee97bd8ba3e88b10ef193fa
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
---
 src/quick/items/qquickrendercontrol.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp
index e433e55873..a666bb59c9 100644
--- a/src/quick/items/qquickrendercontrol.cpp
+++ b/src/quick/items/qquickrendercontrol.cpp
@@ -172,6 +172,10 @@ void QQuickRenderControlPrivate::windowDestroyed()
 /*!
   Initializes the scene graph resources. The context \a gl has to
   be the current context.
+
+  \note Qt Quick does not take ownership of the context. It is up to the
+  application to destroy it after a call to invalidate() or after the
+  QQuickRenderControl instance is destroyed.
  */
 void QQuickRenderControl::initialize(QOpenGLContext *gl)
 {
@@ -274,7 +278,6 @@ void QQuickRenderControl::invalidate()
     // application right after returning from this function. Invalidating is
     // also essential to allow a subsequent initialize() to succeed.
     d->rc->invalidate();
-    QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
 
     d->initialized = false;
 }
-- 
GitLab