Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove obsolete check on FlutterPlatformViewsController::OnCreate #19819

Merged
merged 5 commits into from
Jul 16, 2020

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Jul 16, 2020

Description

When initially landed (92944f7), this check made sense. After #9075 we no longer need to touch the flutter_view_ directly in OnCreate.

A recent change to lifecycle logic means that we sometimes get these calls (particularly on application relaunch for reasons I don't grasp) in different orders sometimes. Specifically, we no longer let viewDidLayoutSubviews create the surface unless the application is active - and sometimes get to that point (it's called before applicationBecameActive).

I'm not able to make this fail in local app that actually calls it in this order. I have to think about how to test this.

Related Issues

Fixes flutter/flutter#23787
Fixes flutter/flutter#61584

Tests

I added the following tests:

Test that we can successfully create a platform view without a flutter_view_.

@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@dnfield dnfield requested a review from gaaclarke July 16, 2020 20:00
@@ -122,15 +122,6 @@
}

void FlutterPlatformViewsController::OnCreate(FlutterMethodCall* call, FlutterResult& result) {
if (!flutter_view_.get()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this race condition be moved to a different part of the code after this change? What about ensuring that flutter_view_ isn't null in the other parts of the code where it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my own auditing of the code, no. We're no longer creating a FlutterView here, we're creating a different UI view that's delegating based on the VC rather than the View.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. I think we should make sure we are confident to say that the flutter_view_ is ready when the platform view is going to be displayed.(when Rasterizer:Draw happens)
What about we assert that in CompositeWithParams? Or even earlier in PrerollCompositeEmbeddedView

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't have a rasterizer without a surface (which the Flutter View creates).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I meant that since we are confident that if the Rasterizer:Draw is called, the flutter_view_ should not nil, we can assert the flutter_view_ in either CompositeWithParams or PrerollCompositeEmbeddedView.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the animator won't be started unless you have a surface either - so there won't be any composition/preroll calls without a surface (-> view)

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read through the code for FlutterPlatformViewsController and didn't see an obvious crash that could result from flutter_view_ being nil. It is usually used in identity comparisons and the target for objc messages.

Amir said we could get rid of the error when flutter/flutter#23787 is addressed, which it isn't addressed yet officially, fwiw.

I find this hard to reason about since we can't know when flutter_view_ is getting set by just reading the code. At some point it shouldn't be nil right? It seems like we should push this assert down lower to things logic that assumes it's not nil.

@dnfield
Copy link
Contributor Author

dnfield commented Jul 16, 2020

I've written a test case that passes in headless mode. I'm not clear on what's left toa ddress for that.

@dnfield
Copy link
Contributor Author

dnfield commented Jul 16, 2020

I'm hoping @cyanglaz can confirm, but I believe some of his previous work has actually fixed #23787 indirectly. I think my test case proves that.

@cyanglaz
Copy link
Contributor

@dnfield you are right. We are not relying on the FlutterView when creating the PlatformView. We only needed the FlutterView when we attach the PlatformView to it.
I saw that there is one instance that we are replying on the bounds of the FlutterView to determine the size of the Overlay: https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm#L637
Though I think this line is not necessary as the overlay's frame should be later determined by the RTree work @blasten has done.

@dnfield
Copy link
Contributor Author

dnfield commented Jul 16, 2020

The GetLayer call happens from SubmitFrame, which also only is called if the animator is enabled and the rasterizer is working - which require a view/surface. I thnk that should be safe, but happy to add some DCHECKs to it if that would help.

@dnfield
Copy link
Contributor Author

dnfield commented Jul 16, 2020

@godofredoc @digiter - I'm not sure why the mac builds are failing here. It's https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket.appspot.com/8874586729338893104/+/steps/lint_test/0/stdout - seems like Xcode might not be installed on teh bot(s)?

@cyanglaz
Copy link
Contributor

The GetLayer call happens from SubmitFrame, which also only is called if the animator is enabled and the rasterizer is working - which require a view/surface. I thnk that should be safe, but happy to add some DCHECKs to it if that would help.

A DCheck in any of the places sounds good. It might help future debugging.

@dnfield
Copy link
Contributor Author

dnfield commented Jul 16, 2020

Sprinkled those into the methods that seem to need them :)

@@ -472,6 +466,7 @@
bool FlutterPlatformViewsController::SubmitFrame(GrContext* gr_context,
std::shared_ptr<IOSContext> ios_context,
std::unique_ptr<SurfaceFrame> frame) {
FML_DCHECK(flutter_view_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is good enough, I'm ok with removing the other ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought is that these are free outside debug mode, and this will help clarify things if we refactor any of this in the future. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, SG! We probably don't need the one in PrerollCompositeEmbeddedView, as it seems this method doesn't use flutter_view_ at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jul 16, 2020
@dnfield
Copy link
Contributor Author

dnfield commented Jul 16, 2020

Engine redness is due to bad recipe land that I've reverted. I'm going to land this on red to kick the build.

@dnfield dnfield merged commit 3d104f4 into flutter:master Jul 16, 2020
@dnfield dnfield deleted the ios_fix branch July 16, 2020 22:37
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 17, 2020
dnfield added a commit to dnfield/engine that referenced this pull request Jul 17, 2020
Remove obsolete check on FlutterPlatformViewsController::OnCreate (flutter#19819)
dnfield added a commit that referenced this pull request Jul 17, 2020
* Cherry pick 3d104f4

Remove obsolete check on FlutterPlatformViewsController::OnCreate (#19819)

* Migrating web_analysis from Cirrus to LUCI (PART 1) (#19726)

* explicitly check out framework rc branch

Co-authored-by: nturgut <nurhan@google.com>
Co-authored-by: Christopher Fujino <christopherfujino@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
6 participants