Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[CP] [Windows] Fix headless mode crash #38233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref) {

bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine,
const char* entry_point) {
return EngineFromHandle(engine)->Run(entry_point);
std::string_view entry_point_view{""};
if (entry_point != nullptr) {
entry_point_view = entry_point;
}

return EngineFromHandle(engine)->Run(entry_point_view);
}

uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) {
Expand Down
10 changes: 10 additions & 0 deletions shell/platform/windows/flutter_windows_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ TEST_F(WindowsTest, LaunchCustomEntrypointInEngineRunInvocation) {
ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), "customEntrypoint"));
}

// Verify that the engine can launch in headless mode.
TEST_F(WindowsTest, LaunchHeadlessEngine) {
auto& context = GetContext();
WindowsConfigBuilder builder(context);
EnginePtr engine{builder.InitializeEngine()};
ASSERT_NE(engine, nullptr);

ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), nullptr));
}

// Verify that engine fails to launch when a conflicting entrypoint in
// FlutterDesktopEngineProperties.dart_entrypoint and the
// FlutterDesktopEngineRun parameter.
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/windows/public/flutter_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ FLUTTER_EXPORT bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine);
// set in the dart_entrypoint field of the FlutterDesktopEngineProperties
// struct passed to FlutterDesktopEngineCreate.
//
// If sprecified, entry_point must be the name of a top-level function from the
// If specified, entry_point must be the name of a top-level function from the
// same Dart library that contains the app's main() function, and must be
// decorated with `@pragma(vm:entry-point)` to ensure the method is not
// tree-shaken by the Dart compiler. If conflicting non-null values are passed
Expand Down