Application crashes on exit when I close the main window, but not when I use quit menu... help?

[quote=383640:@Roger Clary]If you put

autoquit = True
in the app.Open event I bet that solves your problem as your app will quit when you close the last window[/quote]

I’m a little reticent to try this simply because I want to have full control over when the app quits - not have it be triggered as a side effect. I suppose I could try moving my clean up code to the app.close event, and set autoquit = true.

With autoquit=true, can I guarantee that app.close() will always fire when the app autoquits?

@Kimball Larsen - Use Trixie’s declare above. It sorts it. Just place it in your CancelClose event for the Main window of the app.

@Tim Jones : Thanks! I used Trixie’s declare (massaged slightly for use in my app.shutdown method rather than in the window close or cancelClose event), and the crash has disappeared:

[code]//exit the process
#if TargetWindows
quit
#elseif 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]

I watched the video, but was looking for the crash log, sorry I didn’t notice it :slight_smile:

[quote=383752:@Kimball Larsen]@Christian Schmitz - in your feedback report referenced above (#51965) you commented:
Where, specifically should I put this loop?

Thanks![/quote]

I have it in app.open where I setup the containers.

The terminate declare may not be a good thing as all the destructors may not fire, so app may close without proper cleanup!

[quote=383657:@Beatrix Willius]Post the crash log.

I seem to remember that quitting in 64bit was discussed before. My problem is that 64bit doesn’t quit at all. A declare was posted which solves this problem:

[code]#if Target64Bit 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]

This cleanly terminates the app.[/quote]

Be very careful with this if you put it in App,CancelClose, it will prevent you from returning True to stop the app from closing - for instance, if there’s unsaved data.

That is exactly the point my dear fellow. The crashes are occurring somewhere in the wind-down process.

BTW, an application needs to use Terminate to exit if you want to take advantage of Window preservation in the macOS.

Just for the record: It was Sam Rowlands declare. :wink:

I use it in every project now. Without this declare, your app will crash at random sooner or later (if running macOS10.13).