juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.48k stars 1.71k forks source link

[Bug]: SystemStats::setApplicationCrashHandler() never get called on crash on Mac/Win #1175

Open mikegazzaruso opened 1 year ago

mikegazzaruso commented 1 year ago

Detailed steps on how to reproduce the bug

Tested on both Standalone Plugin and Basic GUI Application.

1) Create JUCE App 2) Try to set a crash handler i.e. in MainComponent.cpp

juce::SystemStats::setApplicationCrashHandler([](void* crashData){
        DBG("CRASHED");
        [... your crash handling code ...]
    });

3) Try to trigger a crash later in the code, i.e. when pressing a button:

 button.onClick = [](){
        abort();
    };

Also tried different approaches to trigger the crash, like assigning a value to a nullptr, or raise(SIGILL) etc., no way. The code inside the handler is never called, and the IP will never stop on a breakpoint inside it.

What is the expected behaviour?

The Crash Handler is invoked and the crash handling code is executed.

Operating systems

Windows, macOS

What versions of the operating systems?

Windows 10, Mac OS 12

Architectures

x86_64, ARM, 64-bit

Stacktrace

No response

Plug-in formats (if applicable)

VST3, AUv3, Standalone

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct

chromadevlabs commented 1 year ago

This is normal behaviour. Your debugger will catch most 'exceptions' before user code.

abort() and the like will typically emit a 'debug break' opcode, which will not be caught by your exception handler regardless.

Disable 'invalid access' exception handling in your debugger and try something like throw nullptr. You can test this by having your handler emit something to stdout and running your application from the command line/terminal.

This works for me:

SystemStats::setApplicationCrashHandler ([] (void*) 
{
    printf ("Caught crash!\n");});
});
Timer::callAfterDelay (1000, [] { throw nullptr; });

image