Crash an application on NSException

Ok so now the App crashes all the time with the following

Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: exc handler [5130]

Application Specific Information:
Crashing on exception: -[XOJCanvasView setImageFrameStyle:]: unrecognized selector sent to instance 0x7f94c3d4f860

Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff38de2b57 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff71c5e5bf objc_exception_throw + 48
2 CoreFoundation 0x00007fff38e61be7 -[NSObject(NSObject) __retain_OA] + 0
3 CoreFoundation 0x00007fff38d473bb forwarding + 1427
4 CoreFoundation 0x00007fff38d46d98 _CF_forwarding_prep_0 + 120
5 Cargo Australia.debug 0x000000010112f498 GameWnd.GameWnd.PlayerShip1_Open%%o<GameWnd.GameWnd>o + 360
6 Cargo Australia.debug 0x00000001011c00d4 Delegate.IM_Invoke%%o + 52
7 Cargo Australia.debug 0x00000001011c0124 AddHandler.Stub.2%% + 52
8 XojoFramework 0x0000000101944d3a FireWindowOpenEvents + 184
9 Cargo Australia.debug 0x0000000100ed4dcc Window.Constructor%%o + 60
10 Cargo Australia.debug 0x00000001011bfa8d GameWnd.GameWnd%o<GameWnd.GameWnd>% + 589
11 Cargo Australia.debug 0x0000000101396d6a _MakeDefaultView + 106
12 Cargo Australia.debug 0x0000000101396fcf _LateStartup + 79
13 XojoFramework 0x00000001017afd1d _Z29CocoaFinishApplicationStartupv + 185

And there you go. Somewhere in your code you’re trying to call setImageFrameStyle: on a Canvas and not an Imagewell.

Bingo I was just back stepping duplicated the project and stepped through with the changes until it happened again. I had several Imagewells that don’t really work in Windows for what I was doing and I simply went through and changed their supers to canvas and kept all the names the same but lurking in the open events of the image wells I was turning the frame off with a declare
 :slight_smile: Thanks Sam for the replies

1 Like

Glad I could help. When I saw your post, I immediately thought it sounded like the macOS swallowing the exception rather than reporting it.

I’ve added a comment from Jeff Johnson where he mentions a scenario where NSApplicationCrashOnException will not fire.

1 Like

My application plist has

<key>NSApplicationCrashOnExceptions</key>
<true/>

and yet in macOS Big Sur, it’s not crashing during exceptions.

In this case, the exception happens during a DragItem.

There are 3 items on the pasteboard, but 1 drag images. There must be 1 draggingItem per pasteboardItem.
com.apple.AppKit	error	AppKit	General	There are 3 items on the pasteboard, but 1 drag images. There must be 1 draggingItem per pasteboardItem.
	0   CoreFoundation                      0x00007fff2063783b __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff2036fd92 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff2063769f +[NSException raise:format:] + 189
	3   AppKit                              0x00007fff2310a460 -[NSDraggingSession(NSInternal) _initWithPasteboard:image:offset:source:] + 245
	4   AppKit                              0x00007fff23109e98 -[NSCoreDragManager dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] + 1767
	5   AppKit                              0x00007fff231097a2 -[NSWindow(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] + 134
	6   XojoFramework.dylib                 0x000000010677a312 _Z16CocoaPerformDragP14DragItemObject + 2718
	7   MyApp             0x00000001047f3474 DragItem.Drag%%o<DragItem> + 36

I’ve fixed this particular crash, but the fact that it silently fails was really hard to debug.

Does NSApplicationCrashOnExceptions no longer work? Or am I doing it wrong?

From what I’m reading, this isn’t a plist entry item but an NSUserDefaults entry.

I also have an MBS license so this looked like the solution to the problem. I get a “This item does not exist” with “NSApplicationCrashOnExceptions” highlighted.

In that code snippet "NSApplicationCrashOnExceptions" is a string, so be sure you’ve carried over all the quotes as double-quotes and not curly-quotes.

3 Likes

Thank you Tim. That was the issue. These old eyes missed it.

I’ve had that happen so often I wrote a Code Assistant to replace curly quotes with straight ones.
Screenshot 2023-02-19 at 8.02.11 AM

1 Like