JUCE icon indicating copy to clipboard operation
JUCE copied to clipboard

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

Open mikegazzaruso opened this issue 2 years ago • 1 comments
trafficstars

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 ...]
    });
  1. 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

mikegazzaruso avatar Dec 22 '22 14:12 mikegazzaruso

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

chromadevlabs avatar Jan 09 '23 11:01 chromadevlabs