From 3a30a2733fbdaf510931c57a9c815dcabcfcaa02 Mon Sep 17 00:00:00 2001 From: Evert-Jan de Bruin Date: Fri, 27 Jun 2025 20:10:22 +0200 Subject: [PATCH] Bugfix: No implementation found for the method ensureInitialized when performing a hot restart (15). --- windows/window_manager_plus_plugin.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/windows/window_manager_plus_plugin.cpp b/windows/window_manager_plus_plugin.cpp index baa13189..661961f9 100644 --- a/windows/window_manager_plus_plugin.cpp +++ b/windows/window_manager_plus_plugin.cpp @@ -1,4 +1,4 @@ -#include "include/window_manager_plus/window_manager_plus_plugin.h" +#include "include/window_manager_plus/window_manager_plus_plugin.h" // This must be included before many other Windows headers. #include @@ -455,13 +455,22 @@ void WindowManagerPlusPlugin::HandleMethodCall( if (method_name.compare("ensureInitialized") == 0) { if (windowId >= 0) { + // if this method is called when window manager already exists, this may be due to a hot restart in flutter. + // Clear the old channel if applicable. + auto it = WindowManagerPlus::windowManagers_.find(windowId); + if (it != WindowManagerPlus::windowManagers_.end()) { + auto existing_manager = it->second; + if (existing_manager->channel) { + existing_manager->channel->SetMethodCallHandler(nullptr); + existing_manager->channel.reset(); // clear old channel + } + } + window_manager->id = windowId; window_manager->native_window = ::GetAncestor(registrar->GetView()->GetNativeWindow(), GA_ROOT); - if (window_manager->channel) { - window_manager->channel->SetMethodCallHandler(nullptr); - } + // create new channel window_manager->channel = std::make_unique>( registrar->messenger(),