77#include " MRPch/MRWasm.h"
88#include < GLFW/glfw3.h>
99
10+ #ifdef _WIN32
11+ #include < excpt.h>
12+ #endif
13+
1014#if defined( __EMSCRIPTEN__ ) && !defined( __EMSCRIPTEN_PTHREADS__ )
1115namespace
1216{
@@ -119,6 +123,7 @@ void ProgressBar::orderWithMainThreadPostProcessing( const char* name, TaskWithM
119123
120124 instance.progress_ = 0 .0f ;
121125
126+ instance.task_ = task;
122127 instance.currentTask_ = 0 ;
123128 if ( taskCount == 1 )
124129 instance.currentTask_ = 1 ;
@@ -132,15 +137,15 @@ void ProgressBar::orderWithMainThreadPostProcessing( const char* name, TaskWithM
132137 ImGui::OpenPopup ( instance.setupId_ );
133138 instance.lastPostEvent_ = std::chrono::system_clock::now ();
134139#if !defined( __EMSCRIPTEN__ ) || defined( __EMSCRIPTEN_PTHREADS__ )
135- instance.thread_ = std::thread ( [task, &instance] ()
140+ instance.thread_ = std::thread ( [&instance] ()
136141 {
137142 SetCurrentThreadName ( " ProgressBar" );
138- instance.tryRunTask_ ( task );
143+ instance.tryRunTaskWithSehHandler_ ( );
139144 } );
140145#else
141- staticTaskForLaterCall = [&instance, task ] ()
146+ staticTaskForLaterCall = [&instance] ()
142147 {
143- instance.tryRunTask_ ( task );
148+ instance.tryRunTaskWithSehHandler_ ( );
144149 };
145150 emscripten_async_call ( asyncCallTask, nullptr , 200 );
146151#endif
@@ -249,11 +254,14 @@ ProgressBar::~ProgressBar()
249254 thread_.join ();
250255}
251256
252- void ProgressBar::tryRunTask_ ( TaskWithMainThreadPostProcessing task )
257+ void ProgressBar::tryRunTask_ ()
253258{
259+ #ifndef NDEBUG
260+ onFinish_ = task_ ();
261+ #else
254262 try
255263 {
256- onFinish_ = task ();
264+ onFinish_ = task_ ();
257265 }
258266 catch ( const std::bad_alloc& badAllocE )
259267 {
@@ -273,6 +281,28 @@ void ProgressBar::tryRunTask_( TaskWithMainThreadPostProcessing task )
273281 menu->showErrorModal ( msg );
274282 };
275283 }
284+ #endif
285+ }
286+
287+ void ProgressBar::tryRunTaskWithSehHandler_ ()
288+ {
289+ #if !defined(_WIN32) || !defined(NDEBUG)
290+ tryRunTask_ ();
291+ #else
292+ __try
293+ {
294+ tryRunTask_ ();
295+ }
296+ __except ( EXCEPTION_EXECUTE_HANDLER )
297+ {
298+ onFinish_ = []()
299+ {
300+ spdlog::error ( " Unknown exception occurred" );
301+ if ( auto menu = getViewerInstance ().getMenuPlugin () )
302+ menu->showErrorModal ( " Unknown exception occurred" );
303+ };
304+ }
305+ #endif
276306 finish_ ();
277307}
278308
0 commit comments