From 1b215e6c063f5bad18a09e247d2f18fade7dfdc8 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 22 Sep 2021 11:46:45 +0300 Subject: [PATCH] libkwineffects: Avoid accessing effects in EffectQuickView EffectQuickView is used by Aurorae. As long as Aurorae decorations are rendered by kwin, it's not a problem. However, kde-gtk-config kded module can also render them. This creates a problem. If effects object is not created, accessing any of its getters or setters will result in a segmentation fault. This change rewrites the share context check so the effects object is not accessed anymore. One could argue that kde-gtk-config has to provide a dummy EffectsHandler but it doesn't use effects and libkwineffects is not a dependency of KDecoration2. So, providing a dummy EffectsHandler makes no sense. In hindsight, we need to revisit the usage of EffectQuickView in Aurorae as accessing the EffectsHandler in EffectQuickView is a totally valid usecase and integration of QOpenGLContext. BUG: 441585 --- src/libkwineffects/kwineffectquickview.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libkwineffects/kwineffectquickview.cpp b/src/libkwineffects/kwineffectquickview.cpp index 23005d58af..fe8fdfffe2 100644 --- a/src/libkwineffects/kwineffectquickview.cpp +++ b/src/libkwineffects/kwineffectquickview.cpp @@ -120,8 +120,9 @@ EffectQuickView::EffectQuickView(QObject *parent, QWindow *renderWindow, ExportM format.setDepthBufferSize(16); format.setStencilBufferSize(8); + auto shareContext = QOpenGLContext::globalShareContext(); d->m_glcontext.reset(new QOpenGLContext); - d->m_glcontext->setShareContext(QOpenGLContext::globalShareContext()); + d->m_glcontext->setShareContext(shareContext); d->m_glcontext->setFormat(format); d->m_glcontext->create(); @@ -134,8 +135,8 @@ EffectQuickView::EffectQuickView(QObject *parent, QWindow *renderWindow, ExportM d->m_renderControl->initialize(d->m_glcontext.data()); d->m_glcontext->doneCurrent(); - // On Wayland, opengl contexts are implicitly shared. - if (!effects->waylandDisplay() && !d->m_glcontext->shareContext()) { + // On Wayland, contexts are implicitly shared and QOpenGLContext::globalShareContext() is null. + if (shareContext && !d->m_glcontext->shareContext()) { qCDebug(LIBKWINEFFECTS) << "Failed to create a shared context, falling back to raster rendering"; // still render via GL, but blit for presentation d->m_useBlit = true;