diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart index dbffdd7f3..5d19b850c 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/custom_platform_view.dart @@ -362,14 +362,14 @@ class _CustomPlatformViewState extends State _reportSurfaceSize(); _reportWidgetPosition(); - if (!_focusNode.hasFocus) { - _focusNode.requestFocus(); - Future.delayed(const Duration(milliseconds: 50), () { - if (!_focusNode.hasFocus) { - _focusNode.requestFocus(); - } - }); - } + // if (!_focusNode.hasFocus) { + // _focusNode.requestFocus(); + // Future.delayed(const Duration(milliseconds: 50), () { + // if (!_focusNode.hasFocus) { + // _focusNode.requestFocus(); + // } + // }); + // } _pointerKind = ev.kind; if (ev.kind == PointerDeviceKind.touch) { diff --git a/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.cc b/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.cc index 2bbc1e748..4d0405892 100644 --- a/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.cc +++ b/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.cc @@ -22,6 +22,20 @@ namespace flutter_inappwebview_plugin valid_ = true; } + GraphicsContext::~GraphicsContext() + { + // Explicitly release DirectX resources to prevent hanging process + if (device_context_) { + device_context_->ClearState(); + device_context_->Flush(); + device_context_ = nullptr; + } + + device_winrt_ = nullptr; + device_ = nullptr; + valid_ = false; + } + winrt::com_ptr GraphicsContext::CreateCompositor() { diff --git a/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.h b/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.h index 883bffe71..6af731840 100644 --- a/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.h +++ b/flutter_inappwebview_windows/windows/custom_platform_view/graphics_context.h @@ -12,6 +12,7 @@ namespace flutter_inappwebview_plugin class GraphicsContext { public: GraphicsContext(rx::RoHelper* rohelper); + ~GraphicsContext(); inline bool IsValid() const { return valid_; } diff --git a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp index 8a03dbd33..11451f278 100644 --- a/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp +++ b/flutter_inappwebview_windows/windows/in_app_webview/in_app_webview_manager.cpp @@ -256,6 +256,26 @@ namespace flutter_inappwebview_plugin keepAliveWebViews.clear(); windowWebViews.clear(); UnregisterClass(windowClass_.lpszClassName, nullptr); + + // Properly cleanup static DirectX resources to prevent hanging process + if (compositor_) { + // Release the extra reference we added in constructor + compositor_->Release(); + compositor_ = nullptr; + } + + // Reset graphics context to release DirectX resources + graphics_context_.reset(); + + // Cleanup dispatcher queue controller + if (dispatcher_queue_controller_) { + dispatcher_queue_controller_ = nullptr; + } + + // Reset RoHelper + rohelper_.reset(); + + valid_ = false; plugin = nullptr; } }