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

Commit 7260e84

Browse files
author
Chris Yang
committed
only add transcations on main thread
1 parent 249bcf7 commit 7260e84

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

shell/platform/darwin/ios/ios_surface.mm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@
7171
TRACE_EVENT0("flutter", "IOSSurface::CancelFrame");
7272
FML_CHECK(platform_views_controller_ != nullptr);
7373
platform_views_controller_->CancelFrame();
74-
// Committing the current transaction as |BeginFrame| will create a nested
75-
// CATransaction otherwise.
76-
[CATransaction commit];
74+
if ([[NSThread currentThread] isMainThread]) {
75+
// Committing the current transaction as |BeginFrame| will create a nested
76+
// CATransaction otherwise.
77+
[CATransaction commit];
78+
}
7779
}
7880

7981
// |ExternalViewEmbedder|
@@ -84,7 +86,9 @@
8486
TRACE_EVENT0("flutter", "IOSSurface::BeginFrame");
8587
FML_CHECK(platform_views_controller_ != nullptr);
8688
platform_views_controller_->SetFrameSize(frame_size);
87-
[CATransaction begin];
89+
if ([[NSThread currentThread] isMainThread]) {
90+
[CATransaction begin];
91+
}
8892
}
8993

9094
// |ExternalViewEmbedder|
@@ -102,7 +106,7 @@
102106
TRACE_EVENT0("flutter", "IOSSurface::PostPrerollAction");
103107
FML_CHECK(platform_views_controller_ != nullptr);
104108
PostPrerollResult result = platform_views_controller_->PostPrerollAction(raster_thread_merger);
105-
if (result == PostPrerollResult::kSkipAndRetryFrame) {
109+
if (result == PostPrerollResult::kSkipAndRetryFrame && [[NSThread currentThread] isMainThread]) {
106110
// Commit the current transaction if the frame is dropped.
107111
[CATransaction commit];
108112
}
@@ -129,7 +133,7 @@
129133
bool submitted =
130134
platform_views_controller_->SubmitFrame(std::move(context), ios_context_, std::move(frame));
131135

132-
if (submitted) {
136+
if (submitted && [[NSThread currentThread] isMainThread]) {
133137
TRACE_EVENT0("flutter", "IOSSurface::DidSubmitFrame");
134138
[CATransaction commit];
135139
}

0 commit comments

Comments
 (0)