@@ -106,10 +106,18 @@ int run_program(int argc, char *argv[]){
106106 QDir ().mkpath (QString::fromStdString (SETTINGS_PATH ()));
107107 QDir ().mkpath (QString::fromStdString (SCREENSHOTS_PATH ()));
108108
109+
110+
109111 // Preload all the cameras now so we don't hang the UI later on.
110- ScopeExit cameras ([]{ GlobalMediaServices::instance ().stop (); });
112+ ScopeExit cameras ([]{
113+ GlobalMediaServices::instance ().stop ();
114+ });
111115 get_all_cameras ();
112116
117+ // Force all the Qt thread pools to be constructed now on the main thread.
118+ GlobalThreadPools::qt_worker_threadpool ();
119+ GlobalThreadPools::qt_event_threadpool ();
120+
113121 // Several novice developers struggled to build and run the program due to missing Resources folder.
114122 // Add this check to pop a message box when Resources folder is missing.
115123 if (!check_resource_folder (logger)){
@@ -226,15 +234,20 @@ int main(int argc, char *argv[]){
226234 global_watchdog ().stop ();
227235 static_cast <FileWindowLogger&>(global_logger_raw ()).stop ();
228236
237+ // When we actually migrate to Qt 6.9+, we may need to move the exit(0)
238+ // call here since joining *any* threads may hang.
239+
229240 // Force stop the thread pools.
241+ // This is where all the threads in the program are joined.
230242 PokemonAutomation::GlobalThreadPools::computation_realtime ().stop ();
231243 PokemonAutomation::GlobalThreadPools::computation_normal ().stop ();
232244 PokemonAutomation::GlobalThreadPools::unlimited_realtime ().stop ();
233245 PokemonAutomation::GlobalThreadPools::unlimited_normal ().stop ();
234- GlobalThreadPools::qt_worker_threadpool ().stop ();
235-
236246 PokemonAutomation::global_dispatcher.stop ();
237247
248+ GlobalThreadPools::qt_worker_threadpool ().stop ();
249+ GlobalThreadPools::qt_event_threadpool ().stop ();
250+
238251 cout << " Exiting main()..." << endl;
239252
240253
0 commit comments