EimaMei / Silicon

An alternative, purely C-focused wrapper to Apple's Cocoa API for OS X app development and basic iOS programming. Requires little to no Objective-C knowledge to use.
Other
19 stars 2 forks source link

Apple M2 + Sonoma: Save-file example crashes. #7

Closed g40 closed 11 months ago

g40 commented 11 months ago

Hello.

save-file example crashes running under lldb after compiling with clang. lldb trace shown below.

Any thoughts?


Current executable set to '/Users/jevans/src/osx/Silicon-h/save-file' (arm64).
(lldb) r
Process 17950 launched: '/Users/jevans/src/osx/Silicon-h/save-file' (arm64)
2023-11-27 16:44:58.359539+0000 save-file[17950:2642947] [General] -[NSWindow OnButtonClick]: unrecognized selector sent to instance 0x129709fb0
2023-11-27 16:44:58.362152+0000 save-file[17950:2642947] [General] (
    0   CoreFoundation                      0x000000018ddce800 __exceptionPreprocess + 176
    1   libobjc.A.dylib                     0x000000018d8c5eb4 objc_exception_throw + 60
    2   CoreFoundation                      0x000000018de803bc -[NSObject(NSObject) __retain_OA] + 0
    3   CoreFoundation                      0x000000018dd38a84 ___forwarding___ + 1572
    4   CoreFoundation                      0x000000018dd383a0 _CF_forwarding_prep_0 + 96
    5   AppKit                              0x00000001916d8464 -[NSApplication(NSResponder) sendAction:to:from:] + 460
    6   AppKit                              0x00000001916d8268 -[NSControl sendAction:to:] + 72
    7   AppKit                              0x00000001916d81ac __26-[NSCell _sendActionFrom:]_block_invoke + 100
    8   AppKit                              0x00000001916d80d4 -[NSCell _sendActionFrom:] + 204
    9   AppKit                              0x00000001916d7ff8 -[NSButtonCell _sendActionFrom:] + 88
    10  AppKit                              0x00000001916d5628 NSControlTrackMouse + 1480
    11  AppKit                              0x00000001916d5034 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 144
    12  AppKit                              0x00000001916d4eec -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 488
    13  AppKit                              0x00000001916d43c0 -[NSControl mouseDown:] + 448
    14  AppKit                              0x00000001916d318c -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 3472
    15  AppKit                              0x000000019165e690 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 364
    16  AppKit                              0x000000019165e350 -[NSWindow(NSEventRouting) sendEvent:] + 284
    17  AppKit                              0x0000000191d07f30 -[NSApplication(NSEventRouting) sendEvent:] + 1604
    18  AppKit                              0x000000019195a110 -[NSApplication _handleEvent:] + 60
    19  AppKit                              0x0000000191526124 -[NSApplication run] + 512
    20  save-file                           0x000000010000197c NSApplication_run + 36
    21  save-file                           0x0000000100001330 main + 676
    22  dyld                                0x000000018d9010e0 start + 2360
)
ColleagueRiley commented 11 months ago

Hey, is this a problem with silicon.h? If so it might be better to put the issue in that repository instead. I don't think Eima minds however.

I'll look into the issue later.

ColleagueRiley commented 11 months ago

The crash seems to be caused by the ARM processor. However, even when running the program using x86 it outputs

2023-11-27 17:02:24.327 save-file[1430:17137] -[NSWindow OnButtonClick]: unrecognized selector sent to instance 0x7f940ad0bb50

Meaning the same issue is happening, just on ARM it results in a crash. This should be relatively easy to fix.

g40 commented 11 months ago

@ColleagueRiley Hello,

I'd agree re ARM64. Quite possibly related to the last problem.

BTW I am commenting here because issues are unavailable on your fork.

ColleagueRiley commented 11 months ago

Oh, that's strange. Github acts a little strange when it comes to forks.

But the issue should be solved now. It was more so an issue on my part and how I misinterpreted some code for the original example.

g40 commented 11 months ago

Well, one thing at a time.

It might be a good idea to add "-g -o0" to the clang command line in the meantime so debug info is maintained.

In respect of the latter:

Current executable set to '/Users/jevans/src/osx/Silicon-h/save-file' (arm64).
(lldb) r
Process 18887 launched: '/Users/jevans/src/osx/Silicon-h/save-file' (arm64)
2023-11-27 23:06:50.194143+0000 save-file[18887:2762430] [General] *** +[NSSavePanel<0x1e3e61dc8> init]: cannot init a class object.
2023-11-27 23:06:50.197646+0000 save-file[18887:2762430] [General] (
    0   CoreFoundation                      0x000000018ddce800 __exceptionPreprocess + 176
    1   libobjc.A.dylib                     0x000000018d8c5eb4 objc_exception_throw + 60
    2   CoreFoundation                      0x000000018de80690 +[NSObject(NSObject) dealloc] + 0
    3   save-file                           0x0000000100000aa8 NSInit + 36
    4   save-file                           0x000000010000095c OnButtonClick + 48
    5   AppKit                              0x00000001916d8464 -[NSApplication(NSResponder) sendAction:to:from:] + 460
    6   AppKit                              0x00000001916d8268 -[NSControl sendAction:to:] + 72
    7   AppKit                              0x00000001916d81ac __26-[NSCell _sendActionFrom:]_block_invoke + 100
    8   AppKit                              0x00000001916d80d4 -[NSCell _sendActionFrom:] + 204
    9   AppKit                              0x00000001916d7ff8 -[NSButtonCell _sendActionFrom:] + 88
    10  AppKit                              0x00000001916d5628 NSControlTrackMouse + 1480
    11  AppKit                              0x00000001916d5034 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 144
    12  AppKit                              0x00000001916d4eec -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 488
    13  AppKit                              0x00000001916d43c0 -[NSControl mouseDown:] + 448
    14  AppKit                              0x00000001916d318c -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 3472
    15  AppKit                              0x000000019165e690 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 364
    16  AppKit                              0x000000019165e350 -[NSWindow(NSEventRouting) sendEvent:] + 284
    17  AppKit                              0x0000000191d07f30 -[NSApplication(NSEventRouting) sendEvent:] + 1604
    18  AppKit                              0x000000019195a110 -[NSApplication _handleEvent:] + 60
    19  AppKit                              0x0000000191526124 -[NSApplication run] + 512
    20  save-file                           0x000000010000188c NSApplication_run + 36
    21  save-file                           0x0000000100001108 main + 688
    22  dyld                                0x000000018d9010e0 start + 2360
)
ColleagueRiley commented 11 months ago

Is that output after the update? Is it still not working for you?

g40 commented 11 months ago

I do believe so.

ColleagueRiley commented 11 months ago

I do believe so.

Well, the first issue was solved. But this actually helps a lot because I was just doing some testing and realized the function randomly stopped working running NSInit() (and returning to main on it's own)

So this actually shows that NSInit has some sort of error. That's weird that the x84 version doesn't even care to tell you that there was an issue and just leaves you to guess.

ColleagueRiley commented 11 months ago

Okay, so it turned out there were two issues (with the last issue that you hadn't gotten two yet) 1) a missing replacement function 2) I messed something up when fixing the casting issue

Point being, both those issues are fixed now and the example should work as intended.

g40 commented 11 months ago

Excellent. The save-file example= works. I'll let you know if any other problems emerge. Thanks.