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

Accessing UIScreen.mainScreen in +load results in deadlock while injecting test bundle in Xcode 16 #56

Open
macdrevx opened this issue Aug 7, 2024 · 7 comments · May be fixed by #57 or #58
Open

Comments

@macdrevx
Copy link

macdrevx commented Aug 7, 2024

Also filed with Apple as FB14703057 (Deadlock in UIKit while injecting test bundle).

Steps to repro:

  1. Create a new iOS project and install STULabel
  2. Open the workspace with Xcode 16 beta 5
  3. Run the unit tests

Actual behavior:

Tests fail to launch due to deadlock

Expected behavior:

Tests run

--

Deadlock occurs inside of the UIScreen.mainScreen access initiated by +load added in the category on UIScreen.

@macdrevx
Copy link
Author

I shared this issue on the Apple Dev Forums: https://developer.apple.com/forums/thread/762078

The recommendation is that we should update this to avoid using UIKit prior to main, which implies not using it in +load.

@nolanw
Copy link

nolanw commented Aug 27, 2024

Here's my fix: https://github.com/happybits/STULabel/blob/eded97a3db8e4b104848aebe33c8e9121ab174d1/STULabel/STUMainScreenProperties.m#L60 I lazy-load on first access of the exported stu_mainScreen…() functions, with a main thread check to avoid deadlock.

If that solution looks appealing then I'd happily open a PR, just let me know.

@macdrevx
Copy link
Author

sounds promising. could you go ahead and open the PR so we can see the diff more easily?

@nolanw nolanw linked a pull request Aug 28, 2024 that will close this issue
@nolanw
Copy link

nolanw commented Aug 28, 2024

@macdrevx done!

@stephan-tolksdorf
Copy link
Owner

@macdrevx Thank you for reporting this issue!

Did you already get any reply from Apple on the feedback issue, other than the forum reply?

Are you aware of any documentation implying that UIKit methods can't be called prior to main?

@macdrevx
Copy link
Author

@stephan-tolksdorf the reply on the forums is the only one I received. I'm not aware of any statement in the docs about using UIKit prior to main.

@macdrevx
Copy link
Author

macdrevx commented Sep 4, 2024

@stephan-tolksdorf looks like you received a reply from Apple on the forums post: https://developer.apple.com/forums//thread/762078?answerId=802399022#802399022

stephan-tolksdorf added a commit that referenced this issue Sep 29, 2024
@stephan-tolksdorf stephan-tolksdorf linked a pull request Sep 29, 2024 that will close this issue
stephan-tolksdorf added a commit that referenced this issue Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants