openbakery/InstanceHelper

App crashes if scene(_:willConnectTo:options:) contains a different common setup

Closed this issue · 4 comments

The test test_window_is_created_on_willConnectTo() causes my app to crash with message "Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)" if the scene delegate contains the following common programmatic setup:

guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = UINavigationController(rootViewController: ViewController())
window?.makeKeyAndVisible()

I get this on a plain project that I've just added the instance helper files to and removed the storyboard from.

Substituting the above implementation with the one portrayed on GitHub solves the issue.

Have you disable the Thread and Address Sanitizer?

Hi René,

Thank you for your code and for your prompt reply.

I think they are off:
Screenshot 2023-12-06 alle 16 22 24

Here is the project if there's anything else you need to know: https://drive.google.com/drive/folders/1YjYVf9Nd5MedzihOgNsQFuSLAFsyuz7q?usp=share_link

Create the window using this line then it works:

window = UIWindow(windowScene: windowScene)

Right. Thank you very much