JUCE
JUCE copied to clipboard
[Bug]: SystemStats::setApplicationCrashHandler() never get called on crash on Mac/Win
Detailed steps on how to reproduce the bug
Tested on both Standalone Plugin and Basic GUI Application.
- Create JUCE App
- Try to set a crash handler i.e. in MainComponent.cpp
juce::SystemStats::setApplicationCrashHandler([](void* crashData){
DBG("CRASHED");
[... your crash handling code ...]
});
- 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
- [X] I agree to follow the Code of Conduct
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; });
