mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Catch unhandled exceptions in background processing, call
wxApp::OnUnhandledException()
This commit is contained in:
		
							parent
							
								
									0ac17b5513
								
							
						
					
					
						commit
						7c934ef951
					
				
					 2 changed files with 12 additions and 1 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| #include "BackgroundSlicingProcess.hpp" | ||||
| #include "GUI_App.hpp" | ||||
| 
 | ||||
| #include <wx/app.h> | ||||
| #include <wx/event.h> | ||||
| #include <wx/panel.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.
 | ||||
| } | ||||
| 
 | ||||
| void BackgroundSlicingProcess::thread_proc_safe() | ||||
| { | ||||
| 	try { | ||||
| 		this->thread_proc(); | ||||
| 	} catch (...) { | ||||
| 		wxTheApp->OnUnhandledException(); | ||||
|    	} | ||||
| } | ||||
| 
 | ||||
| void BackgroundSlicingProcess::join_background_thread() | ||||
| { | ||||
| 	std::unique_lock<std::mutex> lck(m_mutex); | ||||
|  | @ -127,7 +137,7 @@ bool BackgroundSlicingProcess::start() | |||
| 	if (m_state == STATE_INITIAL) { | ||||
| 		// The worker thread is not running yet. Start it.
 | ||||
| 		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.
 | ||||
| 		m_condition.wait(lck, [this](){ return m_state == STATE_IDLE; }); | ||||
| 	} | ||||
|  |  | |||
|  | @ -80,6 +80,7 @@ public: | |||
| 
 | ||||
| private: | ||||
| 	void 	thread_proc(); | ||||
| 	void 	thread_proc_safe(); | ||||
| 	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.
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 bubnikv
						bubnikv