Pulley icon indicating copy to clipboard operation
Pulley copied to clipboard

Pulley hangs on iOS 14 Beta 4

Open florianbuerger opened this issue 5 years ago • 65 comments

After upgrading to iOS 14 Beta 4, even the example projects won't launch anymore and the CPU is at 100%. I didn't have time to investigate further so I don't know if this is a bug from iOS 14 or Pulley. It worked fine until iOS 14 Beta 3.

Anyway, a short term fix I found is to slightly delay the layout code for Pulley with a good old DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) — which, in my initial testing — seems to resolve the issue. See for an example https://github.com/florianbuerger/Pulley/commit/ea6c287f4153e510ede4baffd0e3c96bb6a000e0

Just wanted to leave that here in case anyone else is running into it.

florianbuerger avatar Aug 05 '20 12:08 florianbuerger

This bug started showing up in 14b4, it's an auto layout loop caused by calling view.setNeedsLayout() inside of override open func viewDidLayoutSubviews() when setting the value on the variable currentDisplayMode. For now I've removed the view.setNeedsLayout() from the variable setter, but it might cause unexpected behavior when changing the drawer display mode after it is drawn.

My guess is that this bug is being caused by a faster UI drawing brought by the latest beta, which causes a new re-draw while the call to viewDidLayoutSubviews() hasn't finished yet, you can run your projects with the launch argument -UIViewLayoutFeedbackLoopDebuggingThreshold 100 to better debug this issue.

rafaelfrancisco-dev avatar Aug 06 '20 13:08 rafaelfrancisco-dev

Here's a good summary on how to debug auto-layout feedback loops.

andreyz avatar Aug 11 '20 12:08 andreyz

FYI still occurs on Beta 5.

pmacro avatar Aug 18 '20 19:08 pmacro

Around line 597:

changing this:

    public fileprivate(set) var currentDisplayMode: PulleyDisplayMode = .automatic {
        didSet {
            if self.isViewLoaded
            {
                self.view.setNeedsLayout()
            }

            if oldValue != currentDisplayMode
            {

to this:

    public fileprivate(set) var currentDisplayMode: PulleyDisplayMode = .automatic {
        didSet {
            if oldValue != currentDisplayMode
            {
                if self.isViewLoaded
                {
                    self.view.setNeedsLayout()
                }

Fixes it. I don't know this feature or codebase well enough to judge the implications of not running setNeedsLayout when old and new values are the same.

pmacro avatar Aug 18 '20 20:08 pmacro

I can confirm this issue. Still present on beta 5.

@pmacro Thank you for providing a proposal for a fix! Are you able to open a PR with the fix?

funkenstrahlen avatar Aug 19 '20 07:08 funkenstrahlen

@funkenstrahlen we only use drawer mode, so my workaround may not work in all cases. I think someone who knows the codebase, and all edge cases, or who has time to discover them, would be better placed to fix this. I posted the workaround mainly to help anyone else who's trying to test the rest of their app for iOS 14 launch.

pmacro avatar Aug 19 '20 22:08 pmacro

Hey! Thanks everyone for looking into this issue as I have not had a chance to dive into Xcode 12 yet. I have created the xcode12 branch to start looking into the beta issues with iOS 14 and have included the above patch for this issue, as well as the fix for if the drawer in panel mode and the display mode does not transition. Please continue to test on this branch and let me know what you run into in the betas leading up to the iOS 14 release.

ulmentflam avatar Aug 20 '20 14:08 ulmentflam

Thank you for providing the xcode12 branch with the fix. It does actually improve the situation as the app does not hang on startup anymore.

However when I try to manually change the pulley position state it still starts to hang in an infinite loop.

funkenstrahlen avatar Sep 01 '20 11:09 funkenstrahlen

Hi! When can we expect an updated version of the SDK with the fix?

stevi-clue avatar Sep 07 '20 07:09 stevi-clue

@florianbuerger is this infinite loop happening when you call setDrawerPosition(position, animated, completion?)?

ulmentflam avatar Sep 07 '20 20:09 ulmentflam

@ulmentflam I am not 100% sure what you mean. Do you mean in the patched version I linked in my first message?

We have been using Pulley with that fix for a while now and we didn't encounter any more problems. There are no hangs anymore. We are calling setDrawerPosition(position, animated, completion?) often and also directly after launching the app to restore a saved drawer position. We are also using the panel mode on iPad, no issues there as well.

I haven't had time to check out the xcode12 branch.

florianbuerger avatar Sep 08 '20 10:09 florianbuerger

I'm sorry @florianbuerger, I did mean to tag @funkenstrahlen in my question above who is testing on the xcode12 branch. However, it is good to know that you are not experiencing any other hanging issues with a slight delay in the layout code as I continue to investigate.

ulmentflam avatar Sep 08 '20 14:09 ulmentflam

@ulmentflam Ah, got it 😄 I'll see if I can test the xcode12 branch this week. Not sure if we need anything else from my fork of Pulley, it has been a while since I looked at that part of the app.

florianbuerger avatar Sep 08 '20 15:09 florianbuerger

Hi, I have tried this branch in xcode 12 but app hangs on launch. but it is working fine with xcode 11.

Hey! Thanks everyone for looking into this issue as I have not had a chance to dive into Xcode 12 yet. I have created the xcode12 branch to start looking into the beta issues with iOS 14 and have included the above patch for this issue, as well as the fix for if the drawer in panel mode and the display mode does not transition. Please continue to test on this branch and let me know what you run into in the betas leading up to the iOS 14 release.

sohail-niazi avatar Sep 14 '20 11:09 sohail-niazi

@sohail-niazi are you using Xcode 12 Beta 6?

ulmentflam avatar Sep 14 '20 16:09 ulmentflam

@sohail-niazi are you using Xcode 12 Beta 6?

yes it is Xcode 12 beta 6.

sohail-niazi avatar Sep 14 '20 18:09 sohail-niazi

Hi @ulmentflam, I fully understand all the moving parts here, and that this may be an unreasonable question! But given the announcement that iOS 14 will be released tomorrow, could you please share your thoughts on the timing of this fix? Do you plan to have a compatible release ASAP, or do you plan to hold off until there is more clarity on reported issues, such as @sohail-niazi's? That information would help me, and hopefully others, who plan to release iOS 14 updates for their apps ASAP. Thank you!

pmacro avatar Sep 15 '20 18:09 pmacro

@pmacro I am planning to hold off until there is more clarity on the reported issues before getting this branch out specifically. I would like to get more clarity on @sohail-niazi's and @funkenstrahlen's issues before I release (as on the sample project I have not been able to replicate either of their issues on this branch). I want to get a fix for this issue out as soon as possible, as soon as I have clarity on these existing issues. That leads me to my next question for @sohail-niazi, Can you replicate this issue in the demo project for me?

ulmentflam avatar Sep 15 '20 19:09 ulmentflam

Unfortunately I will not be able to provide further input to this issue. I decided to go with a completely different approach and use system default modal views instead of Pulley in my app as I am trying to get the app compatible with macOS. This will be more easy with default system components in my case.

funkenstrahlen avatar Sep 16 '20 08:09 funkenstrahlen

@ulmentflam We can reproduce this issue in two of our apps with latest stable version. After applying the xcode12 branch of this repo our views work as expected and we could so far not detect any other side effects.

pschneider avatar Sep 16 '20 14:09 pschneider

@ulmentflam I have tried demo project for xcode12 branch. It works fine but still I cant make it work(my project) on ios14, ios13 is running fine. I have vereified xcode12 branch changes after pod install. But App just gets stuck on launch and no logs even.

UPDATE: Demo project too is hanging on Start ... Steps to reproduce error: 1 - UnComment programatical loading of pulleyViewController and add primary/drawer views 2 - set initial position .closed and app hangs.

sohail-niazi avatar Sep 16 '20 18:09 sohail-niazi

@sohail-niazi have you made any customizations or tweeks to Pulley, or have you subclassed it?

ulmentflam avatar Sep 16 '20 18:09 ulmentflam

@sohail-niazi have you made any customizations or tweeks to Pulley, or have you subclassed it?

No.. I am using base PulleyViewController in my application.

I was able to reproduce error on demo project. Steps to reproduce error: 1 - UnComment programatical loading of pulleyViewController and add primary/drawer views 2 - set initial position .closed and app hangs.

sohail-niazi avatar Sep 16 '20 18:09 sohail-niazi

@sohail-niazi That's great! It looks like there is still an auto-layout feedback loop when the initial drawer position is set. I am looking into it now, thanks for the feedback!

ulmentflam avatar Sep 16 '20 19:09 ulmentflam

@ulmentflam Apparently PulleyViewController is running in infinite loop. It's viewDidLayoutSubviews() method is getting called in loop... And getting this message in UIMainApplication after applying breakpoint in PulleyViewController : "Application violated contract by causing UIApplicationMain() to return. This incident will be reported."

sohail-niazi avatar Sep 16 '20 19:09 sohail-niazi

@sohail-niazi That's great! It looks like there is still an auto-layout feedback loop when the initial drawer position is set. I am looking into it now, thanks for the feedback!

Much appreciated speedy response. Thanks...

sohail-niazi avatar Sep 16 '20 19:09 sohail-niazi

@funkenstrahlen I know you are no longer using Pulley for your application, but were you by chance changing the position of the drawer to or from the .closed position?

ulmentflam avatar Sep 17 '20 01:09 ulmentflam

@funkenstrahlen I know you are no longer using Pulley for your application, but were you by chance changing the position of the drawer to or from the .closed position?

Yes that's exactly what I did and that also caused the same 'hang' symptom.

funkenstrahlen avatar Sep 17 '20 03:09 funkenstrahlen

@funkenstrahlen Thank you! This auto-layout loop is related to when the view is laid out in the .closed position. For everyone on this branch or waiting on this issue, I have been debugging this loop and will get the xcode12 branch released as soon as there is a fix.

ulmentflam avatar Sep 17 '20 14:09 ulmentflam

I just pushed a theoretical fix to the xcode12 branch. If anyone continues to run into issues let me know ASAP, otherwise I will get a release out as soon as there is confirmation that this update is working.

ulmentflam avatar Sep 18 '20 15:09 ulmentflam