Catch unhandled exceptions in background processing, call
wxApp::OnUnhandledException()
This commit is contained in:
parent
0ac17b5513
commit
7c934ef951
@ -1,6 +1,7 @@
|
|||||||
#include "BackgroundSlicingProcess.hpp"
|
#include "BackgroundSlicingProcess.hpp"
|
||||||
#include "GUI_App.hpp"
|
#include "GUI_App.hpp"
|
||||||
|
|
||||||
|
#include <wx/app.h>
|
||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
#include <wx/panel.h>
|
#include <wx/panel.h>
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
@ -103,6 +104,15 @@ void BackgroundSlicingProcess::thread_proc()
|
|||||||
// End of the background processing thread. The UI thread should join m_thread now.
|
// End of the background processing thread. The UI thread should join m_thread now.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BackgroundSlicingProcess::thread_proc_safe()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
this->thread_proc();
|
||||||
|
} catch (...) {
|
||||||
|
wxTheApp->OnUnhandledException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BackgroundSlicingProcess::join_background_thread()
|
void BackgroundSlicingProcess::join_background_thread()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lck(m_mutex);
|
std::unique_lock<std::mutex> lck(m_mutex);
|
||||||
@ -127,7 +137,7 @@ bool BackgroundSlicingProcess::start()
|
|||||||
if (m_state == STATE_INITIAL) {
|
if (m_state == STATE_INITIAL) {
|
||||||
// The worker thread is not running yet. Start it.
|
// The worker thread is not running yet. Start it.
|
||||||
assert(! m_thread.joinable());
|
assert(! m_thread.joinable());
|
||||||
m_thread = std::thread([this]{this->thread_proc();});
|
m_thread = std::thread([this]{this->thread_proc_safe();});
|
||||||
// Wait until the worker thread is ready to execute the background processing task.
|
// Wait until the worker thread is ready to execute the background processing task.
|
||||||
m_condition.wait(lck, [this](){ return m_state == STATE_IDLE; });
|
m_condition.wait(lck, [this](){ return m_state == STATE_IDLE; });
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void thread_proc();
|
void thread_proc();
|
||||||
|
void thread_proc_safe();
|
||||||
void join_background_thread();
|
void join_background_thread();
|
||||||
// To be called by Print::apply() through the Print::m_cancel_callback to stop the background
|
// 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.
|
// processing before changing any data of running or finalized milestones.
|
||||||
|
Loading…
Reference in New Issue
Block a user