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

Commit 2148fc0

Browse files
authored
[Windows] Fix headless mode crash (#38173)
1 parent 8fe61bc commit 2148fc0

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

shell/platform/windows/flutter_windows.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref) {
145145

146146
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine,
147147
const char* entry_point) {
148-
return EngineFromHandle(engine)->Run(entry_point);
148+
std::string_view entry_point_view{""};
149+
if (entry_point != nullptr) {
150+
entry_point_view = entry_point;
151+
}
152+
153+
return EngineFromHandle(engine)->Run(entry_point_view);
149154
}
150155

151156
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) {

shell/platform/windows/flutter_windows_unittests.cc

+10
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ TEST_F(WindowsTest, LaunchCustomEntrypointInEngineRunInvocation) {
8989
ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), "customEntrypoint"));
9090
}
9191

92+
// Verify that the engine can launch in headless mode.
93+
TEST_F(WindowsTest, LaunchHeadlessEngine) {
94+
auto& context = GetContext();
95+
WindowsConfigBuilder builder(context);
96+
EnginePtr engine{builder.InitializeEngine()};
97+
ASSERT_NE(engine, nullptr);
98+
99+
ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), nullptr));
100+
}
101+
92102
// Verify that engine fails to launch when a conflicting entrypoint in
93103
// FlutterDesktopEngineProperties.dart_entrypoint and the
94104
// FlutterDesktopEngineRun parameter.

shell/platform/windows/public/flutter_windows.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ FLUTTER_EXPORT bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine);
147147
// set in the dart_entrypoint field of the FlutterDesktopEngineProperties
148148
// struct passed to FlutterDesktopEngineCreate.
149149
//
150-
// If sprecified, entry_point must be the name of a top-level function from the
150+
// If specified, entry_point must be the name of a top-level function from the
151151
// same Dart library that contains the app's main() function, and must be
152152
// decorated with `@pragma(vm:entry-point)` to ensure the method is not
153153
// tree-shaken by the Dart compiler. If conflicting non-null values are passed

0 commit comments

Comments
 (0)