In my macOS App, I get the nasty "Unexpected outstanding background CATransaction" error and a crash, but only when running from Xcode

Viewed 232

I have an Objective-C macOS application that has a window with essentially a NSTableView on the left and a details view on the right, in a NSSplitView. The window also has labels and other controls. Some of the elements are driven by bindings, some other via referencing outlets. As soon as I open the window, if I don't touch anything, it works. If, as soon as the window opens, I immediately scroll fast with the mouse on any part of the window, I get a crash with this stack trace:

enter image description here

And the nasty "Unexpected outstanding background CATransaction" error in the log. I know this condition is almost always due to an update to the UI in a background thread, but I am checking my code in countless hours and could not find a single update to the UI done in background. The strangest thing is that the crash only occurs when running the app through Xcode. If I run the app from the Finder it never happens. The NSTableView is driven via datasource and delegate, and I tried to remove the connections and it still happens. I tried to exclude parts of the code with a return statement for example in WindowDidLoad, but it still happens. Also removing the bindings did not solve the situation. Can anybody suggest a powerful technique for finding out the instruction causing the crash?

Edit:

I have removed all objects from the window in the NSWindowController and left only the NSScrollView with the embedded NSTableView. It still happens, even if I return manually 0 from numberOfRowsInTableView. I have a possible hint that could lead to a solution: If I set the NSTableView to not enabled, or hidden, or both, it still happens. If I set the NSScrollView to hidden it does not happen any more. I hope this can ring a bell for somebody, as I am really running out of strategies. Thanks again.

2 Answers

I had the same problem when using an NSScrollView & NSSplitView to scroll a long view, and I solved this issue by using a subclass of NSScrollView. No need to add any code in this subclass. I don't know the reason ,but it works.

This is because you are running some UI updates in Background thread. You can resolve the issue by Properly updating UIs in Main thread instead of background threads.

Identify where it shows the error message, put that inside

Dispatchqueue.main.async

Related