Close Window causes crash EXC_BAD_ACCESS (SIGSEGV)

If I have a subwindow open and hit the close button I get a crash in the debugger.
The starting of it is

[quote]Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000020
Exception Note: EXC_CORPSE_NOTIFY[/quote]
Suggestions?

Note: Going to bed

When you get up you can post the relevant part of the crash log (Thread xxx crashed).

Also missing: version of Xojo, version of macOS.

Wasn’t this topic discussed recently? If your problem is the same something with Autoreleasepool should be in the crash log.

MacBookPro Late 2011 (Never Mojave)
No Autoreleasepool
Report::

lCrash report

Go to bed. Here is the relevant part:

1 com.apple.CoreFoundation 0x93740f08 _CFAutoreleasePoolPop + 242 com.apple.Foundation 0x95167f97 -[NSAutoreleasePool drain] +1203 com.apple.AppKit 0x9136fb2a -[NSApplication run] + 9364 XojoFramework 0x00a1b51a mainloop() + 465 XojoFramework 0x00a19628 RuntimeRun + 496 ReviewCards.debug 0x0012a5b1 REALbasic._RuntimeRun + 347 ReviewCards.debug 0x00593261 _Main + 2958 ReviewCards.debug 0x0058f7f9 main + 369 ReviewCards.debug 0x00595038 start + 53

I think this was it: https://forum.xojo.com/50398-question-about-52630-fixed-an-issue-where-macos-apps-could-occa

Add this to App.Close after your code:

[code]#If TargetMacOS Then
Declare Function NSClassFromString Lib “Cocoa” (aClassName As CFStringRef) As Integer
Declare Function sharedApplication Lib “Cocoa” Selector “sharedApplication” (classRef As Integer) As Integer
Declare Sub terminate Lib “Cocoa” Selector “terminate:” (appRef As Integer, sender As Integer)

Dim appInstance As Integer = sharedApplication(NSClassFromString(“NSApplication”))
terminate(appInstance, appInstance)
#EndIf[/code]

Do we know what causes it? Is it XOJO, the OS, or some stuff like declares that are in the code?

Who knows? I got the problem once in a tiny project - like 6 locs. No declares at all. Since I didn’t get the crash again I would assume timing issue and Xojo bug. I didn’t find any Feedback issue for the problem, though.

There is one as a beta bug: <https://xojo.com/issue/52630>

I use those declares with all my macOS projects. It is a Xojo issue but very hard to reproduce and fix.

Nope.
Declares from Tim J didn’t do it.
I also put those Declares at the end of the suspect Windows’ Close event.

I tapped the title bar this time I think.
Thanks for the Feedback case, but it’s different. That is crash on Quit. Mine crashes on stopping (???) quit

I have also been seeing this randomly will all my Xojo apps since installing macOS 10.14.
To me this seems like a macOS bug since I never had this problem before 10.14.
Sometimes it takes closing a particular window 3 or 4 times but eventually it crashes with:

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called
Application Name(1238,0x1126565c0) malloc: Incorrect checksum for freed object 0x7fdf13e5e370: probably modified after being freed.
Corrupt value: 0x7

I have one window and the app that closed recently that crashed.
I don’t have the window’s code yet for the crash, but it also referred to another window as it closes.
They are both from this same app on Mac High Sierra.
I happened to be debugging it just because of this, and it’s basically short.
The app’s code was also at the very end.

If YPUbnd > -1 Then //this is a computed property ClsingNot = False//a property me.RecentItems.SveRecents()//a method YPrf.SavPractWrdFiles(False)//a method End If Return//Return or end of App
The app crashed at the very end.
Thoughts?

Looks like I can’t blame macOS 10.14. I’m seeing this crash on High Sierra as well.
I thought it may be related to timers on the window but I also have a window with no timers that randomly crashes when closed… weird. I will keep experimenting.

I can see the crash on 10.11.6 …

I’ve also seen it on 10.11 and 10.12.

Feedback bug filed 53670.
Sorry, I cannot figure out to paste this as a link.
If you have any info like a crashreport, it would be good to file this as I have to report this as inconsistent and therefore probably not reproducible.

[quote=408775:@Tim Jones]Add this to App.Close after your code:

[code]#If TargetMacOS Then
Declare Function NSClassFromString Lib “Cocoa” (aClassName As CFStringRef) As Integer
Declare Function sharedApplication Lib “Cocoa” Selector “sharedApplication” (classRef As Integer) As Integer
Declare Sub terminate Lib “Cocoa” Selector “terminate:” (appRef As Integer, sender As Integer)

Dim appInstance As Integer = sharedApplication(NSClassFromString(“NSApplication”))
terminate(appInstance, appInstance)
#EndIf[/code][/quote]
Sorry Tim, but this does not fix the problem.
I added your code to my app, and still see the bug.

and it’s not on window.close, it’s more on app.quit that I see this bug.

I too and on two different project, I put in the windows of the buttons “close” with as code “nomdefenetre. close” and there it no longer crashes…

french :
moi aussi et sur deux projet different, j’ai mis dans les fentres des boutons “Fermer” avec comme code “nomdefenetre.close” et l a ne plante plus du tout…

Have you tried adding it to App.Close instead?

I’ve added it to the App.close, at the end of the method, after all other code.
I see the bug when I quit the app, without closing all the windows, it often happens
it did not happen before 2018r2