Win32 specific: SEH handler on background thread. Catches Windows

structured exceptions (hard crashes, segmentation faults...),
converts them to Slic3r::HardCrash exceptions and displays the exception
using the usual PrusaSlicer way.
The SEH handler is installed on the main background slicing thread
as of now, therefore hard crashes in TBB worker threads are not handled.
This commit is contained in:
Vojtech Bubnik 2021-06-22 09:53:23 +02:00
parent c64ce8777f
commit c0715866ff
3 changed files with 154 additions and 17 deletions

View file

@ -174,7 +174,16 @@ public:
private:
void thread_proc();
void thread_proc_safe();
// Calls thread_proc(), catches all C++ exceptions and shows them using wxApp::OnUnhandledException().
void thread_proc_safe() throw();
#ifdef _WIN32
// Wrapper for Win32 structured exceptions. Win32 structured exception blocks and C++ exception blocks cannot be mixed in the same function.
// Catch a SEH exception and return its ID or zero if no SEH exception has been catched.
unsigned long thread_proc_safe_seh() throw();
// Calls thread_proc_safe_seh(), rethrows a Slic3r::HardCrash exception based on SEH exception
// returned by thread_proc_safe_seh() and lets wxApp::OnUnhandledException() display it.
void thread_proc_safe_seh_throw() throw();
#endif // _WIN32
void join_background_thread();
// To be called by Print::apply() through the Print::m_cancel_callback to stop the background
// processing before changing any data of running or finalized milestones.
@ -187,6 +196,20 @@ private:
// Temporary: for mimicking the fff file export behavior with the raster output
void process_sla();
// Call Print::process() and catch all exceptions into ex, thus no exception could be thrown
// by this method. This exception behavior is required to combine C++ exceptions with Win32 SEH exceptions
// on the same thread.
void call_process(std::exception_ptr &ex) throw();
#ifdef _WIN32
// Wrapper for Win32 structured exceptions. Win32 structured exception blocks and C++ exception blocks cannot be mixed in the same function.
// Catch a SEH exception and return its ID or zero if no SEH exception has been catched.
unsigned long call_process_seh(std::exception_ptr &ex) throw();
// Calls call_process_seh(), rethrows a Slic3r::HardCrash exception based on SEH exception
// returned by call_process_seh().
void call_process_seh_throw(std::exception_ptr &ex) throw();
#endif // _WIN32
// Currently active print. It is one of m_fff_print and m_sla_print.
PrintBase *m_print = nullptr;
// Non-owned pointers to Print instances.