Crash When Clicking on Definition View Created by AppKit's showDefinition(for:at)

I'm encountering a crash issue in my macOS application when clicking on the view generated by AppKit's showDefinition(for:at) function. I'm seeking assistance to resolve this issue.

Problem Description:

I'm developing a macOS application where I utilize the showDefinition(for:at) function provided by AppKit to display the definition view of words. However, whenever I click on this view, the application crashes abruptly.

Error Message: The crash log reveals the following error message:

Fault: deferNSXPCInvocationOntoMainThread_block_invoke caught NSInternalInconsistencyException '_CPSSetFrontProcessWithOptions failed due to CGError -606 4294966690 fffffda2 (appIsDaemon)'

Attempts Made:

Tried wrapping relevant code blocks with DispatchQueue.main.async, suspecting a threading issue.

Development Environment:

macOS Version: 14.3.1 Xcode Version: 15.2 I've included a snippet of the function where the view is created:

func showWordDefinition(selectedText: String) {
            DispatchQueue.main.async {
            let DefinitionWindow = NSWindow(contentRect: NSRect(origin: self.mouseLocation, size: NSSize(width: 1, height: 1)), styleMask: [.borderless], backing: .buffered, defer: false)
            DefinitionWindow.level = .floating
            guard let mainScreenFrame = NSScreen.main?.frame else {
                return
            }
            DefinitionWindow.contentView?.showDefinition(for: attributedString, at: pointInWindow)
            DefinitionWindow.orderFront(nil)
}

Potential Questions and Concerns:

Could there be an issue related to UI transitions or the main thread?

How exactly does the showDefinition(for:) process work internally? Maybe , the view's display level being raised when clicked?

If anyone could provide any insights or guidance on resolving this issue, it would be greatly appreciated. Thank you!

Crash When Clicking on Definition View Created by AppKit's showDefinition(for:at)
 
 
Q