diff --git a/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc b/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc index 09df37c355..69bc0677a8 100644 --- a/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc +++ b/engine/src/flutter/shell/platform/glfw/client_wrapper/flutter_window_controller.cc @@ -68,6 +68,14 @@ bool FlutterWindowController::CreateWindow( return true; } +void FlutterWindowController::DestroyWindow() { + if (controller_) { + FlutterDesktopDestroyWindow(controller_); + controller_ = nullptr; + window_ = nullptr; + } +} + FlutterDesktopPluginRegistrarRef FlutterWindowController::GetRegistrarForPlugin( const std::string& plugin_name) { if (!controller_) { @@ -99,9 +107,7 @@ bool FlutterWindowController::RunEventLoopWithTimeout( bool still_running = FlutterDesktopRunWindowEventLoopWithTimeout( controller_, timeout_milliseconds); if (!still_running) { - FlutterDesktopDestroyWindow(controller_); - window_ = nullptr; - controller_ = nullptr; + DestroyWindow(); } return still_running; } diff --git a/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h b/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h index cd4bd58ed0..bb96733e2b 100644 --- a/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h +++ b/engine/src/flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h @@ -69,8 +69,15 @@ class FlutterWindowController : public PluginRegistry { const std::string& assets_path, const std::vector& arguments); + // Destroys the current window, if any. + // + // Because only one window can exist at a time, this method must be called + // between calls to CreateWindow, or the second one will fail. + void DestroyWindow(); + // The FlutterWindow managed by this controller, if any. Returns nullptr - // before CreateWindow is called, and after RunEventLoop returns; + // before CreateWindow is called, after DestroyWindow is called, and after + // RunEventLoop returns; FlutterWindow* window() { return window_.get(); } // Processes the next event on this window, or returns early if |timeout| is