Xcode 13.2 Instantiating CLLocationButton crashes in Simulator

Since updating to Xcode 13.2 (13C90) my App crashes instantly when instantiating a CLLocationButton, but this only happens when running the App in the Simulator.

My setup code looks as follows:


        let button = CLLocationButton()

        button.icon = .arrowOutline

        button.label = .none

        button.cornerRadius = Style.CornerRadius.double

        button.backgroundColor = .white

        button.tintColor = ColorCatalog.Colors.themeColor.color

        button.addTarget(self, action: #selector(userLocationButtonTapped), for: .touchUpInside)

        userLocationButton = button

        view.addSubview(userLocationButton)

        // setting up constraints for CLLocationButton to be on the top right corner

button.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([

            button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16.0),

            button.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16.0)

        ])

    }

On Xcode 13.1, this works just fine. On Xcode 13.2 I get this exception when run in the Simulator:

In the console it prints:

2021-12-14 13:02:13.003747+0100 appname[9412:217536] *** Assertion failure in CGImageRef  _Nonnull UISCreateImageFromDrawing(__strong id _Nonnull, CGFloat, UISDisplayRange)(), UISDrawing.m:19

Replies

After removing references to the code that you don't supply...
...and tweaking what remains, this works for me:

private func setupUserLocationButton() {
        let button = CLLocationButton()
        button.icon = .arrowOutline
        button.label = .none
        button.cornerRadius = 25.0
        button.addTarget(self, action: #selector(userLocationButtonTapped), for: .touchUpInside)
        view.addSubview(button)
        // setting up constraints for CLLocationButton to be on the top right corner
        button.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            button.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16.0),
            button.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16.0)
        ])
    }

Maybe take it from there, and re-add your customizations, one-by-one?

Xcode 13.2 (13C90)
(From the Developer website, not the broken App Store version 13.2)

Thank you for your fast response.

The code I didn't supply was:

private var userLocationButton: CLLocationButton!

the setupUserLocationButton func is called in viewDidLoad

Style.CornerRadius.double is CGFloat = 10.0 and the themeColor is a dark blue

I'm also using Xcode 13.2 (13C90) from the Developer website (never using the App Store version)

with your exact code and assigning "userLocationButton = button", it still crashes when run in the Simulator with:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: width && height'

terminating with uncaught exception of type NSException

CoreSimulator 783.5 - Device: iPhone 13 () - Runtime: iOS 15.2 (19C51) - DeviceType: iPhone 13

  • Is userLocationButton on a Storyboard? Can you try using my code, without userLocationButton first, and see how that works?

  • No, there is no storyboard or xib involved in the whole project. Every UI is written in Code. I tried setting up a new project with your Code above and everything just works fine. I also tried setting up the CLLocationButton in viewDidAppear, on another screen, still crashes in the Simulator. If I initialize the CLLocationButton with a frame, it does not crash but either does not draw the button at all or only shows the button with its backgroundColor, but no icon or text.

    Seems like I'm not the only one experiencing this crash message.

    stackoverflow post describing the same crash message

Add a Comment

there is no storyboard or xib involved

So why are you declaring it like this?

private var userLocationButton: CLLocationButton!

Rather than (say):

private let userLocationButton = CLLocationButton()

...and then set up userLocationButton, rather than bothering with a separate "let button = CLLocationButton()"


Alternatively...

I tried setting up a new project with your Code above and everything just works fine

So just use that code?

So why are you declaring it like this?

This is actually a good question. I've changed it to your suggestion, but it still crashes in the line where it gets instantiated..

So just use that code?

Using your code works fine in a completely fresh project, but in my project it still crashes where it gets instantiated, no matter if using your or my code..

  • That's interesting! I'll have a think about why that might be.

Add a Comment

Just a quick answer before I post a long one: I also stumbled upon this problem, and I managed to create a Minimal Reproductible Example. I'm going to create a GitHub repository with information and all, but basically the steps are:

(Running XCode Version 13.2.1 (13C100))

  1. Create a fresh SwiftUI app
  2. Edit the main App to match
    import SwiftUI
    import CoreLocationUI
    
    @main
    struct CLLocationButtonTesterApp: App {
    	var body: some Scene {
    		WindowGroup {
    			LocationButton(action: {})
    		}
    	}
    }
    
  3. Run the app → no problem
  4. Create an empty file
  5. Add French localization to the app
  6. Add French localization to the file (you can even remove any other *.lproj folder)
  7. Run the app → you get
    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: width && height'
    terminating with uncaught exception of type NSException
    CoreSimulator 783.5 - Device: iPhone 13 (B8BF9672-9A4F-4E59-83EC-4844992B74C4) - Runtime: iOS 15.2 (19C51) - DeviceType: iPhone 13
    

Tip: Clean the build folder between each test, otherwise you might encounter caching issues 😉

  • By the way I still have no idea how to fix it…

  • I found something that's very interesting: my Simulator was using French as its primary language. I I put English as the primary language, the problem goes away 🤩

  • Thanks Rémi !

Add a Comment