From a470a3a842a84ff594248a217c995f4d95fa8785 Mon Sep 17 00:00:00 2001 From: GooRingX Date: Thu, 28 Nov 2024 17:48:36 +0800 Subject: [PATCH 1/2] windows: fix WebViewEnvironment dispose crash --- .../webview_environment/webview_environment.cpp | 15 ++++++++++++--- .../webview_environment/webview_environment.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp b/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp index b1285f01c..1c490c96a 100644 --- a/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp +++ b/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp @@ -103,7 +103,7 @@ namespace flutter_inappwebview_plugin } return S_OK; } - ).Get(), nullptr); + ).Get(), &newBrowserVersionAvailableToken_); failedLog(add_NewBrowserVersionAvailable_HResult); if (auto environment5 = environment_.try_query()) { @@ -122,7 +122,7 @@ namespace flutter_inappwebview_plugin } return S_OK; } - ).Get(), nullptr); + ).Get(), &browserProcessExitedToken_); failedLog(add_BrowserProcessExited_HResult); } @@ -152,7 +152,7 @@ namespace flutter_inappwebview_plugin } return S_OK; } - ).Get(), nullptr); + ).Get(), &processInfosChangedToken_); failedLog(add_ProcessInfosChanged_HResult); } @@ -307,6 +307,15 @@ namespace flutter_inappwebview_plugin WebViewEnvironment::~WebViewEnvironment() { + if (environment_ != nullptr) { + if (auto environment8 = environment_.try_query()) { + auto add_ProcessInfosChanged_HResult = environment8->remove_ProcessInfosChanged(processInfosChangedToken_); + } + if (auto environment5 = environment_.try_query()) { + auto add_BrowserProcessExited_HResult = environment5->remove_BrowserProcessExited(browserProcessExitedToken_); + } + environment_->remove_NewBrowserVersionAvailable(newBrowserVersionAvailableToken_); + } debugLog("dealloc WebViewEnvironment"); environment_ = nullptr; } diff --git a/flutter_inappwebview_windows/windows/webview_environment/webview_environment.h b/flutter_inappwebview_windows/windows/webview_environment/webview_environment.h index ed3dea4c4..7ac937993 100644 --- a/flutter_inappwebview_windows/windows/webview_environment/webview_environment.h +++ b/flutter_inappwebview_windows/windows/webview_environment/webview_environment.h @@ -40,6 +40,9 @@ namespace flutter_inappwebview_plugin private: wil::com_ptr environment_; + EventRegistrationToken processInfosChangedToken_ = { 0 }; + EventRegistrationToken browserProcessExitedToken_ = { 0 }; + EventRegistrationToken newBrowserVersionAvailableToken_ = { 0 }; WNDCLASS windowClass_ = {}; }; } From 7336f7191c2e0dc789a5592316ad07a2af2e8242 Mon Sep 17 00:00:00 2001 From: GooRingX Date: Thu, 28 Nov 2024 18:04:24 +0800 Subject: [PATCH 2/2] Update webview_environment.cpp --- .../windows/webview_environment/webview_environment.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp b/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp index 1c490c96a..2fc73f2ba 100644 --- a/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp +++ b/flutter_inappwebview_windows/windows/webview_environment/webview_environment.cpp @@ -307,12 +307,12 @@ namespace flutter_inappwebview_plugin WebViewEnvironment::~WebViewEnvironment() { - if (environment_ != nullptr) { + if (environment_) { if (auto environment8 = environment_.try_query()) { - auto add_ProcessInfosChanged_HResult = environment8->remove_ProcessInfosChanged(processInfosChangedToken_); + environment8->remove_ProcessInfosChanged(processInfosChangedToken_); } if (auto environment5 = environment_.try_query()) { - auto add_BrowserProcessExited_HResult = environment5->remove_BrowserProcessExited(browserProcessExitedToken_); + environment5->remove_BrowserProcessExited(browserProcessExitedToken_); } environment_->remove_NewBrowserVersionAvailable(newBrowserVersionAvailableToken_); }