[Windows] Fix headless mode crash (flutter/engine#38173)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user