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.
UIFontreturns nil