@@ -178,6 +178,10 @@ class BitcoinCore: public QObject
178178 Q_OBJECT
179179public:
180180 explicit BitcoinCore ();
181+ /* * Basic initialization, before starting initialization/shutdown thread.
182+ * Return true on success.
183+ */
184+ static bool baseInitialize ();
181185
182186public Q_SLOTS:
183187 void initialize ();
@@ -270,26 +274,32 @@ void BitcoinCore::handleRunawayException(const std::exception *e)
270274 Q_EMIT runawayException (QString::fromStdString (GetWarnings (" gui" )));
271275}
272276
277+ bool BitcoinCore::baseInitialize ()
278+ {
279+ if (!AppInitBasicSetup ())
280+ {
281+ return false ;
282+ }
283+ if (!AppInitParameterInteraction ())
284+ {
285+ return false ;
286+ }
287+ if (!AppInitSanityChecks ())
288+ {
289+ return false ;
290+ }
291+ if (!AppInitLockDataDirectory ())
292+ {
293+ return false ;
294+ }
295+ return true ;
296+ }
297+
273298void BitcoinCore::initialize ()
274299{
275300 try
276301 {
277302 qDebug () << __func__ << " : Running initialization in thread" ;
278- if (!AppInitBasicSetup ())
279- {
280- Q_EMIT initializeResult (false );
281- return ;
282- }
283- if (!AppInitParameterInteraction ())
284- {
285- Q_EMIT initializeResult (false );
286- return ;
287- }
288- if (!AppInitSanityChecks ())
289- {
290- Q_EMIT initializeResult (false );
291- return ;
292- }
293303 bool rv = AppInitMain (threadGroup, scheduler);
294304 Q_EMIT initializeResult (rv);
295305 } catch (const std::exception& e) {
@@ -689,23 +699,33 @@ int main(int argc, char *argv[])
689699 if (GetBoolArg (" -splash" , DEFAULT_SPLASHSCREEN) && !GetBoolArg (" -min" , false ))
690700 app.createSplashScreen (networkStyle.data ());
691701
702+ int rv = EXIT_SUCCESS;
692703 try
693704 {
694705 app.createWindow (networkStyle.data ());
695- app.requestInitialize ();
706+ // Perform base initialization before spinning up initialization/shutdown thread
707+ // This is acceptable because this function only contains steps that are quick to execute,
708+ // so the GUI thread won't be held up.
709+ if (BitcoinCore::baseInitialize ()) {
710+ app.requestInitialize ();
696711#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
697- WinShutdownMonitor::registerShutdownBlockReason (QObject::tr (" %1 didn't yet exit safely..." ).arg (QObject::tr (PACKAGE_NAME)), (HWND)app.getMainWinId ());
712+ WinShutdownMonitor::registerShutdownBlockReason (QObject::tr (" %1 didn't yet exit safely..." ).arg (QObject::tr (PACKAGE_NAME)), (HWND)app.getMainWinId ());
698713#endif
699- app.exec ();
700- app.requestShutdown ();
701- app.exec ();
714+ app.exec ();
715+ app.requestShutdown ();
716+ app.exec ();
717+ rv = app.getReturnValue ();
718+ } else {
719+ // A dialog with detailed error will have been shown by InitError()
720+ rv = EXIT_FAILURE;
721+ }
702722 } catch (const std::exception& e) {
703723 PrintExceptionContinue (&e, " Runaway exception" );
704724 app.handleRunawayException (QString::fromStdString (GetWarnings (" gui" )));
705725 } catch (...) {
706726 PrintExceptionContinue (NULL , " Runaway exception" );
707727 app.handleRunawayException (QString::fromStdString (GetWarnings (" gui" )));
708728 }
709- return app. getReturnValue () ;
729+ return rv ;
710730}
711731#endif // BITCOIN_QT_TEST
0 commit comments