Hi everyone, I’m working on a macOS SwiftUI app that integrates a global keyboard shortcut using the old Carbon API (RegisterEventHotKey, InstallEventHandler, etc.). Everything works fine initially, but I’m running into a consistent EXC_BAD_ACCESS (code=EXC_I386_GPFLT) crash when the app is reopened, or sometimes even while drawing on my SwiftUI canvas view. Setup Here’s the relevant setup (simplified): private let hotKeySignature: FourCharCode = 0x626c6e6b // 'blnk' private weak var hotKeyDelegate: AppDelegate? private func overlayHotKeyHandler( _ callRef: EventHandlerCallRef?, _ event: EventRef?, _ userData: UnsafeMutableRawPointer? ) -> OSStatus { guard let appDelegate = hotKeyDelegate else { return noErr } return appDelegate.handleHotKey(event: event) } final class AppDelegate: NSObject, NSApplicationDelegate { private var hotKeyRef: EventHotKeyRef? private var eventHandlerRef: EventHandlerRef? override init() { super.init() hotKeyDelegate = self } func applicationDidFinishLaunching(_ notification: Not
Topic:
UI Frameworks
SubTopic:
SwiftUI