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

Keep rendering to screen in iOS inactive state - #25196

Merged
gaaclarke merged 5 commits into
flutter-team-archive:masterfrom
Kavantix:render-in-inactive
Mar 29, 2021
Merged

gaaclarke merged 5 commits into
flutter-team-archive:masterfrom
Kavantix:render-in-inactive

Conversation

@Kavantix

@Kavantix Kavantix commented Mar 23, 2021 •

Copy link
Copy Markdown
Contributor

This is a recreation of #17396 which was accidently from my master branch and thus causing issues.

It fixes that on iOS currently the ui is not rendered in the inactive state.

Related issues:
flutter/flutter#50732
flutter/flutter#33236
flutter/flutter#71051

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@Kavantix

Copy link
Copy Markdown
Contributor Author

@gaaclarke This line might be why it's still not working.
Also the diff that I currently have is slightly different to the one you had so perhaps the conflict resolution went wrong before?

Let me know if there is anything I can do :)

@gaaclarke
gaaclarke marked this pull request as ready for review March 23, 2021 20:02
@flutter-dashboard

Copy link
Copy Markdown

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.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

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

@gaaclarke

Copy link
Copy Markdown
Contributor

This line might be why it's still not working.

@Kavantix What isn't working? I tested it and it addressed flutter/flutter#71051

@Kavantix

Copy link
Copy Markdown
Contributor Author

Ah that's even better, you mentioned in 71051 that the PR did not solve it.
So probably fixed then by the correct merge :)

@Kavantix

Copy link
Copy Markdown
Contributor Author

But just for my sanity, what's the current plan @gaaclarke?
Do we simply change it to work like this for both openGL and metal or should we make something to differentiate between the two?

@gaaclarke

Copy link
Copy Markdown
Contributor

Yep, as for that line you point out, it might be more correct to be foreground instead of active, but let's error on the side of caution and only change what we have to in order to fix the issue.

what's the current plan

I think we should land this. There is no need to differentiate between OpenGL and Metal. Just because Metal doesn't crash in the background doesn't mean it doesn't create problems. I just fixed a bug where we'd do image uploading when launching the app in the Background state via the GPU. It didn't crash but would result in pink images being drawn.

I just want to test this a bit more manually and try to think if there is some way we could test it automatically (not likely).

@Kavantix

Copy link
Copy Markdown
Contributor Author

Yep, as for that line you point out, it might be more correct to be foreground instead of active, but let's error on the side of caution and only change what we have to in order to fix the issue.

Agreed, when starting the shell it should not matter that much anyways.

I think we should land this. There is no need to differentiate between OpenGL and Metal. Just because Metal doesn't crash in the background doesn't mean it doesn't create problems. I just fixed a bug where we'd do image uploading when launching the app in the Background state via the GPU. It didn't crash but would result in pink images being drawn.
I just want to test this a bit more manually and try to think if there is some way we could test it automatically (not likely).

Alright, the crash isn't that big either right since from the user's point of view the app seemed to just be closed by the os which already happens quite a lot on the older devices that were affected

I'd recommend also testing with background updates disabled in the system settings, should not make much of a difference but you never know ;)

As for automatically testing, perhaps you could test that a spinner keeps spinning while a native alert is being shown?
Or do you specifically mean to test whether or not it crashes?

@gaaclarke

gaaclarke commented Mar 23, 2021 •

Copy link
Copy Markdown
Contributor

Alright, the crash isn't that big either right since from the user's point of view the app seemed to just be closed by the os which already happens quite a lot on the older devices that were affected

Based on the documentation you pointed to, we shouldn't have to worry about the race condition crash when backgrounding an app. That's why I'm comfortable with the change.

While it's true that it might not be the biggest deal for end users if we crashed when backgrounding, Flutter's customers are actually the developers, not the end-users. If the developers are using something like Crashlytics it will show up if 10% of the time the app crashes when it's backgrounded, but the developers won't know under what conditions it crashes. They just know it crashes. That's how the original problem was reported.

@gaaclarke

Copy link
Copy Markdown
Contributor

I'm investigating the test failures. I'm having a hard time figuring out what is going on since there are a few infra bugs happening at the same time. I can reproduce the failures locally, but if I revert the PR I still get the failures. I've also seen tests that fail from the command-line pass from Xcode, too.

I'll give it another try tomorrow, it's very frustrating and I'm not 100% sure the PR is at fault. There is some hacks in the scenario integration tests that might have to be updated. I'm pretty sure this failure isn't indicative of a problem with the PR, but is a problem with the tests.

@gaaclarke

Copy link
Copy Markdown
Contributor

@Kavantix you were right about the initialization of the shell with the gpu disabled if the app is backgrounded. You beautiful random internet person, why didn't I listen to you?

Without that change the platform views controller would initiate a CATransaction, then the frame would get rejected since the GPU was disabled, then the next time we tried to render a frame it would crash because there was an open CATransaction. Listening for the foreground notifications isn't enough because we are already foregrounded by the time we create the shell, we won't receive another notification. I'm surprised it worked with manual testing.

I'll just test this manually with background apps then we should be good.

@Kavantix

Copy link
Copy Markdown
Contributor Author

@Kavantix you were right about the initialization of the shell with the gpu disabled if the app is backgrounded. You beautiful random internet person, why didn't I listen to you?

Haha I don't know, it was only a lucky guess XD.

Without that change the platform views controller would initiate a CATransaction, then the frame would get rejected since the GPU was disabled, then the next time we tried to render a frame it would crash because there was an open CATransaction. Listening for the foreground notifications isn't enough because we are already foregrounded by the time we create the shell, we won't receive another notification. I'm surprised it worked with manual testing.

Makes a lot of sense!

Thanks for taking the time to tackle this!, it has been bugging me ever since I first noticed it (about half a year before I filed the original PR 🙈)

@gaaclarke

Copy link
Copy Markdown
Contributor

(this is running into flakey tests, I'm fixing them here: flutter/flutter#79011)

@gaaclarke
gaaclarke force-pushed the render-in-inactive branch from 2f3bbd0 to 0744c08 Compare March 25, 2021 20:04
@gaaclarke

Copy link
Copy Markdown
Contributor

I'm not sure what's going on here. The tests run fine if executed from Xcode, but they seem to fail when run from the commandline:
Screen Shot 2021-03-29 at 1 56 33 PM

I'll try a bit longer, this is taking way more work than I originally expected.

@gaaclarke

Copy link
Copy Markdown
Contributor

I tested the change manually with apps that launch in the background, just to double check everything is good there. It looks good as I would have expected from the code. I used https://github.com/pawlowskim/headless_mode_images_issue and walked around my block.

@gaaclarke gaaclarke changed the title Render in inactive state Keep rendering to screen in iOS inactive state Mar 29, 2021
@gaaclarke
gaaclarke merged commit 1a6eda5 into flutter-team-archive:master Mar 29, 2021

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oops meant to do this before merging, LGTM

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 30, 2021
chandarrengoog pushed a commit to chandarrengoog/engine that referenced this pull request Mar 30, 2021
duanqz pushed a commit to duanqz/engine that referenced this pull request Apr 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

2 participants