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

Conversation

@chinmaygarde
Copy link
Member

UIKit does not guarantee that the application is in the active state when it
lays out it subviews. However, in viewDidLayoutSubviews, Flutter attempts to
create the render surface and wait for the first frame. These operations require
GPU access which is forbidden when in the background on iOS. This layout while
in the background only seems to happen under very specific circumstances as
described in the reproducible test case. Notably, this behavior cannot be
reproduced when the application is just launched with the "Background Fetch"
XCode run scheme. The other instance of invocations to create the rendering
surface have been audited and I can confirm that those are already in the
correct lifecycle callbacks. This was the only instance where the surface
creation was in a non-lifecycle callback.

This underlying cause here was identified by the enhanced GPU error reporting
introduced in iOS 14. I am not able to submit those patches because the Beta
builders are not available on infra. I will submit those when available so that
issues like this have more actionable error messages in the future.

…tion is active.

UIKit does not guarantee that the application is in the active state when it
lays out it subviews. However, in `viewDidLayoutSubviews`, Flutter attempts to
create the render surface and wait for the first frame. These operations require
GPU access which is forbidden when in the background on iOS. This layout while
in the background only seems to happen under very specific circumstances as
described in the reproducible test case. Notably, this behavior cannot be
reproduced when the application is just launched with the "Background Fetch"
XCode run scheme. The other instance of invocations to create the rendering
surface have been audited and I can confirm that those are already in the
correct lifecycle callbacks. This was the only instance where the surface
creation was in a non-lifecycle callback.

Fixes flutter/flutter#55969
(This issue has a clear reproducible test case and was used as the basis for
verification.)
Fixes flutter/flutter#57676
(This is significantly harder to reproduce but the issue looks to be the same. I
tried this patch on multiple devices overnight and could not reproduce this.)

This underlying cause here was identified by the enhanced GPU error reporting
introduced in iOS 14. I am not able to submit those patches because the Beta
builders are not available on infra. I will submit those when available so that
issues like this have more actionable error messages in the future.
@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.

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.

You might want to try making a unit test for this. If you partial mock the view controller, you can rip out surfaceUpdated and show that it doesn't get called. You'll have to find a way to make it think it isn't active though =T

@chinmaygarde
Copy link
Member Author

You'll have to find a way to make it think it isn't active though =T

I am not able to figure this out. In the meantime, I have verified this with all the devices I have access to. To your point about how the shell is launched when it is initially skipped, I seem to be getting both a viewDidLayoutSubviews and a viewWillAppear: then the application is eventually foregrounded. In both cases, the viewport metrics are non-zero and the launch continues. So I think this patch is safe. I am concerned that we are recreating the surface unnecessarily on launch but I don't think that is a concern for this patch. I filed flutter/flutter#61050 so we can go chase this down.

@chinmaygarde chinmaygarde merged commit 0dc86cd into flutter:master Jul 8, 2020
@chinmaygarde chinmaygarde deleted the xcode12 branch July 8, 2020 00:14
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 8, 2020
dnfield pushed a commit to flutter/flutter that referenced this pull request Jul 8, 2020
* a53782f Roll Skia from 6130d5079d55 to 0c0d8dd6d637 (3 revisions) (flutter/engine#19570)

* 0541502 kick build (flutter/engine#19575)

* 07d5090 Roll Skia from 0c0d8dd6d637 to cf5e35f72130 (13 revisions) (flutter/engine#19573)

* 35b5aa5 switch const finder to package_config (flutter/engine#19576)

* de0932b Manual roll of Dart 06cb010247...69aba23371 (flutter/engine#19577)

* b919945 include list_libraries.dart as a snapshot for fuchsia (flutter/engine#19567)

* 3fe5edf Roll Skia from cf5e35f72130 to b4d60f807dbd (5 revisions) (flutter/engine#19587)

* a15bc1b [CanvasKit] Dispose the overlay surface when a platform view is disposed (flutter/engine#19546)

* 0dc86cd Only attempt surface creation in viewDidLayoutSubviews if the application is active. (flutter/engine#19592)
srujzs pushed a commit to srujzs/engine that referenced this pull request Jul 9, 2020
…tion is active. (flutter#19592)

UIKit does not guarantee that the application is in the active state when it
lays out it subviews. However, in `viewDidLayoutSubviews`, Flutter attempts to
create the render surface and wait for the first frame. These operations require
GPU access which is forbidden when in the background on iOS. This layout while
in the background only seems to happen under very specific circumstances as
described in the reproducible test case. Notably, this behavior cannot be
reproduced when the application is just launched with the "Background Fetch"
XCode run scheme. The other instance of invocations to create the rendering
surface have been audited and I can confirm that those are already in the
correct lifecycle callbacks. This was the only instance where the surface
creation was in a non-lifecycle callback.

Fixes flutter/flutter#55969
(This issue has a clear reproducible test case and was used as the basis for
verification.)
Fixes flutter/flutter#57676
(This is significantly harder to reproduce but the issue looks to be the same. I
tried this patch on multiple devices overnight and could not reproduce this.)

This underlying cause here was identified by the enhanced GPU error reporting
introduced in iOS 14. I am not able to submit those patches because the Beta
builders are not available on infra. I will submit those when available so that
issues like this have more actionable error messages in the future.
@xster
Copy link
Member

xster commented Jul 11, 2020

This underlying cause here was identified by the enhanced GPU error reporting introduced in iOS 14.

Oh cool, do you have a link?

I am not able to submit those patches because the Beta builders are not available on infra.

Umm, @jmagman might be another motivation to move the infra before GM.

@chinmaygarde
Copy link
Member Author

Oh cool, do you have a link?

In this talk, it's the first thing they talk about. Unfortunately, this years videos don't seem to have transcripts yet so you'll have to to seek past the intros.

@jmagman
Copy link
Member

jmagman commented Jul 13, 2020

Umm, @jmagman might be another motivation to move the infra before GM.

I would love to test betas on our infra, so I'm not the party who needs additional motivation. 😄
It's a lot of work for the overloaded infra team, but we may just need to get the mechanism in place sooner rather than later, these issues continuously pop up. \cc @godofredoc

@dnfield
Copy link
Contributor

dnfield commented Jul 16, 2020

This is the cause of flutter/flutter#61584

mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
* a53782f Roll Skia from 6130d5079d55 to 0c0d8dd6d637 (3 revisions) (flutter/engine#19570)

* 0541502 kick build (flutter/engine#19575)

* 07d5090 Roll Skia from 0c0d8dd6d637 to cf5e35f72130 (13 revisions) (flutter/engine#19573)

* 35b5aa5 switch const finder to package_config (flutter/engine#19576)

* de0932b Manual roll of Dart 06cb010247...69aba23371 (flutter/engine#19577)

* b919945 include list_libraries.dart as a snapshot for fuchsia (flutter/engine#19567)

* 3fe5edf Roll Skia from cf5e35f72130 to b4d60f807dbd (5 revisions) (flutter/engine#19587)

* a15bc1b [CanvasKit] Dispose the overlay surface when a platform view is disposed (flutter/engine#19546)

* 0dc86cd Only attempt surface creation in viewDidLayoutSubviews if the application is active. (flutter/engine#19592)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter not rendering text after sitting idle (iOS) Apps launched due to Bluetooth connection render incorrectly

8 participants