diff --git a/modules/gui/qt/maininterface/compositor_x11_uisurface.cpp b/modules/gui/qt/maininterface/compositor_x11_uisurface.cpp
index 63ea2ecbb47bf6847fccec279b2489d5b2de3203..2e82cc8d68f5fee938c95cd5b11d6364e82d8fdf 100644
--- a/modules/gui/qt/maininterface/compositor_x11_uisurface.cpp
+++ b/modules/gui/qt/maininterface/compositor_x11_uisurface.cpp
@@ -89,8 +89,21 @@ CompositorX11UISurface::CompositorX11UISurface(QWindow* window, QScreen* screen)
 
     if (m_context)
     {
-        connect(m_uiWindow, &QQuickWindow::sceneGraphInitialized, this, &CompositorX11UISurface::createFbo);
-        connect(m_uiWindow, &QQuickWindow::sceneGraphInvalidated, this, &CompositorX11UISurface::destroyFbo);
+        connect(m_uiWindow, &QQuickWindow::sceneGraphInitialized, this, [this]() {
+            assert(m_context);
+            const bool ret = m_context->makeCurrent(this);
+            assert(ret); // initial fbo creation must succeed
+            createFbo();
+            m_context->doneCurrent();
+        });
+        connect(m_uiWindow, &QQuickWindow::sceneGraphInvalidated, this, [this]() {
+            assert(m_context);
+            if (Q_LIKELY(m_context->makeCurrent(this)))
+            {
+                destroyFbo();
+                m_context->doneCurrent();
+            }
+        });
     }
 
     connect(m_uiWindow, &QQuickWindow::beforeRendering, this, &CompositorX11UISurface::beforeRendering);
@@ -204,15 +217,16 @@ void CompositorX11UISurface::destroyFbo()
     }
 }
 
-void CompositorX11UISurface::render()
+bool CompositorX11UISurface::render()
 {
     if (!isExposed())
-        return;
+        return false;
 
     if (m_context)
     {
         const bool current = m_context->makeCurrent(this);
-        assert(current);
+        if (!current)
+            return false;
         m_uiRenderControl->beginFrame();
     }
 
@@ -250,6 +264,8 @@ void CompositorX11UISurface::render()
     emit m_uiWindow->frameSwapped();
 
     emit updated();
+
+    return true;
 }
 
 void CompositorX11UISurface::updateSizes()
@@ -411,18 +427,21 @@ bool CompositorX11UISurface::eventFilter(QObject*, QEvent *event)
     return false;
 }
 
-void CompositorX11UISurface::resizeFbo()
+bool CompositorX11UISurface::resizeFbo()
 {
     if (m_rootItem)
     {
         const bool current = m_context->makeCurrent(this);
-        assert(current);
+        if (!current)
+            return false;
         destroyFbo();
         createFbo();
         m_context->doneCurrent();
         updateSizes();
         render();
+        return true;
     }
+    return false;
 }
 
 void CompositorX11UISurface::applyNvidiaWorkaround(QSurfaceFormat &format)
diff --git a/modules/gui/qt/maininterface/compositor_x11_uisurface.hpp b/modules/gui/qt/maininterface/compositor_x11_uisurface.hpp
index 308b5796c6e3da638d43a06da994880de3fab7d1..ad9f359e62cb08e6b2c5f13776b0795be6241bf4 100644
--- a/modules/gui/qt/maininterface/compositor_x11_uisurface.hpp
+++ b/modules/gui/qt/maininterface/compositor_x11_uisurface.hpp
@@ -57,7 +57,7 @@ public:
     explicit CompositorX11UISurface(QWindow* window, QScreen *screen = nullptr);
     ~CompositorX11UISurface();
 
-    virtual void render();
+    virtual bool render();
 
     bool handleWindowEvent(QEvent *event);
 
@@ -89,9 +89,12 @@ protected:
 
     void updateSizes();
 
+    // WARNING: The OpenGL context must be made current against this window before calling these methods:
     void createFbo();
     void destroyFbo();
-    void resizeFbo();
+
+    // NOTE: This method attempts to make the OpenGL context current against this window:
+    bool resizeFbo();
 
 private:
     static void applyNvidiaWorkaround(QSurfaceFormat& format);