[vlc-commits] [Git][videolan/vlc][master] qt: unload the wayland module before its dependencies are gone

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jun 3 18:15:17 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
13f988a2 by Fatih Uzunoglu at 2026-06-03T17:47:53+00:00
qt: unload the wayland module before its dependencies are gone

Destroying the quick view also destroys the surface, we should
unload the module before it potentially accesses the surface.

- - - - -


2 changed files:

- modules/gui/qt/maininterface/compositor_wayland.cpp
- modules/gui/qt/maininterface/compositor_wayland.hpp


Changes:

=====================================
modules/gui/qt/maininterface/compositor_wayland.cpp
=====================================
@@ -54,15 +54,7 @@ CompositorWayland::CompositorWayland(qt_intf_t *p_intf, QObject* parent)
 
 CompositorWayland::~CompositorWayland()
 {
-    if (m_waylandImpl)
-    {
-        if (m_waylandImpl->p_module)
-        {
-            m_waylandImpl->close(m_waylandImpl);
-            module_unneed(m_waylandImpl, m_waylandImpl->p_module);
-        }
-        vlc_object_delete(m_waylandImpl);
-    }
+    unloadWaylandModule();
 }
 
 bool CompositorWayland::init()
@@ -79,6 +71,7 @@ bool CompositorWayland::init()
      * a separate wayland module is used to perform direct wayland calls
      * without requiring Qt module to be directly linked to wayland
      */
+    assert(!m_waylandImpl);
     m_waylandImpl = static_cast<qtwayland_t*>(vlc_object_create(m_intf, sizeof(qtwayland_t)));
     if (!m_waylandImpl)
         return false;
@@ -106,6 +99,8 @@ bool CompositorWayland::makeMainInterface(MainCtx* mainCtx, std::function<void(Q
     m_qmlView->setResizeMode(QQuickView::SizeRootObjectToView);
     m_qmlView->setColor(QColor(Qt::transparent));
 
+    m_qmlView->installEventFilter(this);
+
     m_qmlView->create();
 
     QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
@@ -153,7 +148,12 @@ QWindow* CompositorWayland::interfaceMainWindow() const
 void CompositorWayland::destroyMainInterface()
 {
     unloadGUI();
+    // We still need to call this explicitly, as it seems Qt does not send
+    // the `QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed` event if we
+    // delete the window ourselves:
+    unloadWaylandModule();
     m_qmlView.reset();
+    assert(!m_waylandImpl);
 }
 
 void CompositorWayland::unloadGUI()
@@ -170,6 +170,24 @@ void CompositorWayland::unloadGUI()
     commonGUIDestroy();
 }
 
+bool CompositorWayland::eventFilter(QObject *watched, QEvent *event)
+{
+    switch (event->type())
+    {
+    case QEvent::PlatformSurface:
+        if (watched == m_qmlView.get() &&
+            static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
+        {
+            unloadWaylandModule();
+        }
+        break;
+    default:
+        break;
+    }
+
+    return QObject::eventFilter(watched, event);
+}
+
 Compositor::Type CompositorWayland::type() const
 {
     return Compositor::WaylandCompositor;
@@ -257,6 +275,22 @@ void CompositorWayland::onSurfaceScaleChanged(qreal dpr)
     m_waylandImpl->rescale(m_waylandImpl, dpr);
 }
 
+bool CompositorWayland::unloadWaylandModule()
+{
+    if (m_waylandImpl)
+    {
+        if (m_waylandImpl->p_module)
+        {
+            m_waylandImpl->close(m_waylandImpl);
+            module_unneed(m_waylandImpl, m_waylandImpl->p_module);
+        }
+        vlc_object_delete(m_waylandImpl);
+        m_waylandImpl = nullptr;
+        return true;
+    }
+    return false;
+}
+
 #ifdef QT_WAYLAND_HAS_CUSTOM_MARGIN_SUPPORT
 void CompositorWayland::adjustQuickWindowMask()
 {


=====================================
modules/gui/qt/maininterface/compositor_wayland.hpp
=====================================
@@ -62,6 +62,7 @@ public:
      */
     void unloadGUI() override;
 
+    bool eventFilter(QObject *watched, QEvent *event) override;
 
     QWindow* interfaceMainWindow() const override;
 
@@ -95,6 +96,9 @@ protected slots:
 protected:
     std::unique_ptr<QQuickView> m_qmlView;
     qtwayland_t* m_waylandImpl = nullptr;
+
+private:
+    bool unloadWaylandModule();
 };
 
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/13f988a2e7b29492d6e7c303b90863e8c003656e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/13f988a2e7b29492d6e7c303b90863e8c003656e
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list