Change destruction order to avoid accessing deleted GL resources
Change destruction order to avoid accessing deleted GL resources

This commit fixes a crash when a QQuickCanvas containing a
Text item is destroyed.

202127f860208c21145e05685bc54219e1655dbd in qtbase fixed a
resource leak with QOpenGLMultiGroupSharedResource; resources
were not cleaned up correctly when the associated GL context
(group) was destroyed.

This exposed a bug where QSGDefaultDistanceFieldGlyphCache
(used for Text items) relied on that leakage. In particular,
the glyph cache stores a pointer to a GL resource that it
doesn't own (m_textureData).

If the GL context is deleted and there are no other contexts
in the group, the group and its resources will be deleted.
Subsequently, if the glyph cache accesses the resource pointer
when the Text node is destroyed (via
QSGDefaultDistanceFieldGlyphCache::releaseGlyphs()), we crash.

The GL context is deleted when QQuickCanvasPlainRenderLoop is
destroyed. By moving the deletion of the render loop object to
the end of QQuickCanvas destructor, the canvas nodes get a
chance to clean up the resources they use _before_ the
resources are deleted.

Task-number: QTBUG-22754
Change-Id: Ie8de19a139b4631a16203e63e731feed3d8d64cf
Reviewed-by: Aaron Kennedy <087c9f3fe24ea980d31d6a327c000f1b04b5a585@nokia.com>
Reviewed-by: Samuel Rødal <99126055f8d73e4355b075213322026fa8c060bd@nokia.com>

qmlc/qtdeclarative,mgrunditz/qtdeclarative-2d,corngood/qtdeclarative,qmlc/qtdeclarative,jfaust/qtdeclarative,qmlc/qtdeclarative,mgrunditz/qtdeclarative-2d,jfaust/qtdeclarative,jfaust/qtdeclarative,mgrunditz/qtdeclarative-2d,mgrunditz/qtdeclarative-2d,crobertd/qtdeclarative,matthewvogt/qtdeclarative,qmlc/qtdeclarative,corngood/qtdeclarative,crobertd/qtdeclarative,qmlc/qtdeclarative,corngood/qtdeclarative,matthewvogt/qtdeclarative,corngood/qtdeclarative,mgrunditz/qtdeclarative-2d,crobertd/qtdeclarative,crobertd/qtdeclarative,qmlc/qtdeclarative,jfaust/qtdeclarative,qmlc/qtdeclarative,crobertd/qtdeclarative,corngood/qtdeclarative,mgrunditz/qtdeclarative-2d,matthewvogt/qtdeclarative,corngood/qtdeclarative,crobertd/qtdeclarative,matthewvogt/qtdeclarative,matthewvogt/qtdeclarative,matthewvogt/qtdeclarative,jfaust/qtdeclarative,jfaust/qtdeclarative,corngood/qtdeclarative,mgrunditz/qtdeclarative-2d,qmlc/qtdeclarative,jfaust/qtdeclarative,matthewvogt/qtdeclarative,crobertd/qtdeclarative,matthewvogt/qtdeclarative