From 3871bfc5d3aff45e498fa2944c27e6eb5d146c8e Mon Sep 17 00:00:00 2001
From: SineStriker <trueful@163.com>
Date: 周三, 20 12月 2023 19:56:32 +0800
Subject: [PATCH] Add mac hot-switch implementations

---
 src/core/contexts/win32windowcontext.cpp |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index 3b2d3e8..40fda7c 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -117,7 +117,7 @@
     private:
         DynamicApis() {
 #define DYNAMIC_API_RESOLVE(DLL, NAME)                                                             \
-    p##NAME = reinterpret_cast<decltype(p##NAME)>(DLL.resolve(#NAME))
+  p##NAME = reinterpret_cast<decltype(p##NAME)>(DLL.resolve(#NAME))
 
             QSystemLibrary user32(QStringLiteral("user32"));
             DYNAMIC_API_RESOLVE(user32, GetDpiForWindow);
@@ -985,11 +985,18 @@
     }
 
     void Win32WindowContext::winIdChanged(QWindow *oldWindow, bool isDestroyed) {
-        if (isDestroyed) {
-            removeManagedWindow(reinterpret_cast<HWND>(windowId));
-        } else {
-            removeManagedWindow<false>(reinterpret_cast<HWND>(windowId));
+        Q_UNUSED(isDestroyed)
+
+        // If the original window id is valid, remove all resources related
+        if (windowId) {
+            if (isDestroyed) {
+                removeManagedWindow(reinterpret_cast<HWND>(windowId));
+            } else {
+                removeManagedWindow<false>(reinterpret_cast<HWND>(windowId));
+            }
+            windowId = 0;
         }
+
         if (!m_windowHandle) {
             return;
         }

--
Gitblit v1.9.1