Fixed crash associated with reparenting a QGLWidget
We need to make sure that we don't reset() the context when the QGLWidget is being reparented, as that will lead to the QOpenGLContext being destroyed and not recreated, leading to a crash in makeCurrent(). Also, don't destroy() the widget if it has not yet been created, as in that case there's no ParentAboutToChange event sent. Task-number: QTBUG-31016 Change-Id: I409fff94456802a80bd72b470a6fbaee87505baa Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Andy Nichols <andy.nichols@digia.com>
This commit is contained in:
parent
3c50917a6a
commit
f3aad61120
@ -132,6 +132,7 @@ class Q_OPENGL_EXPORT QGLWidgetPrivate : public QWidgetPrivate
|
||||
public:
|
||||
QGLWidgetPrivate() : QWidgetPrivate()
|
||||
, disable_clear_on_painter_begin(false)
|
||||
, parent_changing(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -142,7 +143,7 @@ public:
|
||||
bool renderCxPm(QPixmap *pixmap);
|
||||
void cleanupColormaps();
|
||||
void aboutToDestroy() {
|
||||
if (glcx)
|
||||
if (glcx && !parent_changing)
|
||||
glcx->reset();
|
||||
}
|
||||
|
||||
@ -153,6 +154,7 @@ public:
|
||||
QGLColormap cmap;
|
||||
|
||||
bool disable_clear_on_painter_begin;
|
||||
bool parent_changing;
|
||||
};
|
||||
|
||||
// QGLContextPrivate has the responsibility of creating context groups.
|
||||
|
@ -362,6 +362,15 @@ void QGLWidgetPrivate::cleanupColormaps()
|
||||
|
||||
bool QGLWidget::event(QEvent *e)
|
||||
{
|
||||
Q_D(QGLWidget);
|
||||
|
||||
// A re-parent will destroy the window and re-create it. We should not reset the context while it happens.
|
||||
if (e->type() == QEvent::ParentAboutToChange)
|
||||
d->parent_changing = true;
|
||||
|
||||
if (e->type() == QEvent::ParentChange)
|
||||
d->parent_changing = false;
|
||||
|
||||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
|
@ -263,10 +263,8 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
|
||||
bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
|
||||
|
||||
// Reparenting toplevel to child
|
||||
if (!(f&Qt::Window) && (oldFlags&Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) {
|
||||
//qDebug() << "setParent_sys() change from toplevel";
|
||||
if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow))
|
||||
q->destroy();
|
||||
}
|
||||
|
||||
adjustFlags(f, q);
|
||||
data.window_flags = f;
|
||||
|
Loading…
Reference in New Issue
Block a user