[vlc-commits] [Git][videolan/vlc][master] qt: do not create platform window in `WinId()` in mainctx_win32.cpp

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Mar 6 14:54:41 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
484506e3 by Fatih Uzunoglu at 2025-03-06T14:27:39+00:00
qt: do not create platform window in `WinId()` in mainctx_win32.cpp

Previously the window handle was retrieved through private platform
interface. It was recently changed to use `QWindow::winId()` instead,
as it is public and more convenient to use.

However, `QWindow::winId()` creates the platform window if it does
not exist. This is normally not a problem, but since `WinId()` is
may be called within the native event handler, it is a problem.

I did not realize that `WinId()` was called at inappropriate times
(either during destruction of the platform window when the window
is destroyed, or after that as we don't want to re-create the platform
window when closing the interface), that's why I did not pay attention
on having a check here. Now that the problem is obvious, we should
fix this mistake made in 7e063c67.

This is trivial to fix, we can simply check if the pointer returned
by either `QWindow::handle()` or `QSurface::surfaceHandle()` is a
null pointer, and return early if it is before calling `QWindow::winId()`.

As a side note, I believe that having a const method named as `winId()`
which mutates the window by creating platform window if it does not
exist is a really bad idea. I really wonder why Qt behaves like that,
especially considering there is already `QWindow::create()` that
creates the platform window.

- - - - -


1 changed file:

- modules/gui/qt/maininterface/mainctx_win32.cpp


Changes:

=====================================
modules/gui/qt/maininterface/mainctx_win32.cpp
=====================================
@@ -107,6 +107,8 @@ namespace  {
 HWND WinId( const QWindow *window )
 {
     assert(window);
+    if (!window->handle())
+        return NULL;
     return reinterpret_cast<HWND>(window->winId());
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/484506e3cd39c6e5551eed440fbb25a174791cca

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/484506e3cd39c6e5551eed440fbb25a174791cca
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list