1

Swift application. I have a Theme class declared including the following:


class Theme {    
    enum Font {
        static let header1         = UIFont(name: "IBM Plex Sans Bold", size: 32)! 
        static let header2         = UIFont(name: "IBM Plex Sans Bold", size: 20)! // Crash
        static let pickerTitleFont = UIFont(name: "IBM Plex Sans Bold", size: 17)!
        static let navBarFont      = UIFont(name: "IBM Plex Sans Bold", size: 28)!  // Crash
    }
}

In appDelegate, I have a routine that sets up a navigation bar appearance proxy,

        let appearance = UINavigationBarAppearance()
        appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white,
                                          NSAttributedString.Key.font: Theme.Font.navBarFont]

Sometimes (very rarely), when running this app, a crash occurs.

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000104d5a7c0
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [19751]

Triggered by Thread:  0


Kernel Triage:
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage


Thread 0 name:
Thread 0 Crashed:
0   ---                             0x0000000104d5a7c0 one-time initialization function for pickerTitleFont + 140
1   ---                             0x0000000104d5a7a4 one-time initialization function for pickerTitleFont + 112
2   libdispatch.dylib               0x00000001b8550f88 _dispatch_client_callout + 20 (object.m:560)
3   libdispatch.dylib               0x00000001b85527d4 _dispatch_once_callout + 32 (once.c:52)
4   ---                             0x0000000104d77104 Theme.Font.navBarFont.unsafeMutableAddressor + 20 (Theme.swift:75)
5   ---                             0x0000000104d77104 AppDelegate.setupNavigationController(root:) + 1188 (AppDelegate.swift:152)

How can this crash be occurring? It's simply accessing a statically defined variable. The crash does not clearly state why the crash occurred.

Its very odd that the crash appears to be caused by accessing Font.navBarFont however lower in the stack trace it says its pickerTitleFont.

This crash has also occurred when accessing header2 font setting the font on a label in a view.

3
  • I think because of some reason system is unable to load the custom font. So that the UIFont returns nil Commented Apr 24, 2023 at 4:44
  • Generally agree, but why? This is a very rare occurrence. The font is present and normally loads fine. Commented Apr 24, 2023 at 4:51
  • since it is very rare it may be a resource shortage or a memory constraint. not sure. Commented Apr 24, 2023 at 6:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.