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

Commit a868499

Browse files
committed
Feedback
1 parent ccf6d76 commit a868499

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

runtime/runtime_controller.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ bool RuntimeController::FlushRuntimeStateToIsolate() {
139139
}
140140

141141
if (!added) {
142-
return false;
142+
FML_LOG(ERROR) << "Failed to flush view #" << view_id
143+
<< ". The Dart isolate may be in an inconsistent state.";
143144
}
144145
}
145146

@@ -156,17 +157,25 @@ bool RuntimeController::FlushRuntimeStateToIsolate() {
156157
void RuntimeController::AddView(int64_t view_id,
157158
const ViewportMetrics& view_metrics,
158159
AddViewCallback callback) {
159-
platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
160-
161160
// If the Dart isolate is not running, |FlushRuntimeStateToIsolate| will
162161
// add the view and invoke the callback when the isolate is started.
163162
auto* platform_configuration = GetPlatformConfigurationIfAvailable();
164163
if (!platform_configuration) {
165164
FML_DCHECK(has_flushed_runtime_state_ == false);
165+
166+
if (pending_add_view_callbacks_.find(view_id) !=
167+
pending_add_view_callbacks_.end()) {
168+
FML_LOG(ERROR) << "View #" << view_id << " is already pending creation.";
169+
callback(false);
170+
return;
171+
}
172+
173+
platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
166174
pending_add_view_callbacks_[view_id] = std::move(callback);
167175
return;
168176
}
169177

178+
platform_data_.viewport_metrics_for_views[view_id] = view_metrics;
170179
bool added = platform_configuration->AddView(view_id, view_metrics);
171180
callback(added);
172181
}

shell/common/shell_unittests.cc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,6 +4771,63 @@ TEST_F(ShellTest, CanRemoveViewBeforeLaunchingIsolate) {
47714771
DestroyShell(std::move(shell), task_runners);
47724772
}
47734773

4774+
// Ensure pending "add views" failures are properly flushed when the Dart
4775+
// isolate is launched.
4776+
TEST_F(ShellTest, IgnoresBadAddViewsBeforeLaunchingIsolate) {
4777+
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
4778+
Settings settings = CreateSettingsForFixture();
4779+
ThreadHost thread_host(ThreadHost::ThreadHostConfig(
4780+
"io.flutter.test." + GetCurrentTestName() + ".",
4781+
ThreadHost::Type::kPlatform | ThreadHost::Type::kRaster |
4782+
ThreadHost::Type::kIo | ThreadHost::Type::kUi));
4783+
TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(),
4784+
thread_host.raster_thread->GetTaskRunner(),
4785+
thread_host.ui_thread->GetTaskRunner(),
4786+
thread_host.io_thread->GetTaskRunner());
4787+
std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
4788+
ASSERT_TRUE(shell);
4789+
4790+
PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell] {
4791+
auto platform_view = shell->GetPlatformView();
4792+
4793+
// Add the same view twice. The second time should fail.
4794+
shell->AddView(123, ViewportMetrics{1, 100, 1, 0, 0},
4795+
[](bool added) { ASSERT_TRUE(added); });
4796+
4797+
shell->AddView(123, ViewportMetrics{1, 200, 1, 0, 0},
4798+
[](bool added) { ASSERT_FALSE(added); });
4799+
4800+
// Add another view. Previous failures should not affect this.
4801+
shell->AddView(456, ViewportMetrics{1, 300, 1, 0, 0},
4802+
[](bool added) { ASSERT_TRUE(added); });
4803+
});
4804+
4805+
bool first_report = true;
4806+
std::map<int64_t, int64_t> view_widths;
4807+
fml::AutoResetWaitableEvent report_latch;
4808+
AddNativeCallback("NativeReportViewWidthsCallback",
4809+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
4810+
EXPECT_TRUE(first_report);
4811+
first_report = false;
4812+
ParseViewWidthsCallback(args, &view_widths);
4813+
report_latch.Signal();
4814+
}));
4815+
4816+
PlatformViewNotifyCreated(shell.get());
4817+
auto configuration = RunConfiguration::InferFromSettings(settings);
4818+
configuration.SetEntrypoint("testReportViewWidths");
4819+
RunEngine(shell.get(), std::move(configuration));
4820+
4821+
report_latch.Wait();
4822+
EXPECT_EQ(view_widths.size(), 3u);
4823+
EXPECT_EQ(view_widths[0], 0);
4824+
EXPECT_EQ(view_widths[123], 100);
4825+
EXPECT_EQ(view_widths[456], 300);
4826+
4827+
PlatformViewNotifyDestroyed(shell.get());
4828+
DestroyShell(std::move(shell), task_runners);
4829+
}
4830+
47744831
TEST_F(ShellTest, RuntimeStageBackendDefaultsToSkSLWithoutImpeller) {
47754832
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
47764833
Settings settings = CreateSettingsForFixture();

0 commit comments

Comments
 (0)