History

Fixed deadlock on start with recent Qt versions

ksuprynowicz committed 3 years ago

Commit 28079eb1 parent 8b9cd842 files · +18 −1Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+13−1
@@ -977,6 +977,12 @@ QSharedPointer<OffscreenUi> getOffscreenUI() { · 976 unmodified lines
977977 #endif
978978 }
979979
980+bool Application::initMenu() {
981+ _isMenuInitialized = false;
982+ qApp->getWindow()->menuBar();
983+ return true;
984+}
985+
980986 Application::Application(
981987 int& argc, char** argv,
982988 const QCommandLineParser& parser,
@@ -985,6 +991,8 @@ Application::Application( · 2 unmodified lines
985991 ) :
986992 QApplication(argc, argv),
987993 _window(new MainWindow(desktop())),
994+ // Menu needs to be initialized before other initializers. Otherwise deadlock happens on qApp->getWindow()->menuBar().
995+ _isMenuInitialized(initMenu()),
988996 _sessionRunTimer(startupTimer),
989997 #ifndef Q_OS_ANDROID
990998 _logger(new FileLogger(this)),
@@ -1017,7 +1025,6 @@ Application::Application( · 26 unmodified lines
10171025 _snapshotSound(nullptr),
10181026 _sampleSound(nullptr)
10191027 {
1020−
10211028 auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
10221029 setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
10231030 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
@@ -4225,6 +4232,11 @@ bool Application::event(QEvent* event) { · 3201 unmodified lines
42254232 return false;
42264233 }
42274234
4235+ // This helps avoid deadlock issue early during Application initialization
4236+ if (!_isMenuInitialized) {
4237+ return QApplication::event(event);
4238+ }
4239+
42284240 if (!Menu::getInstance()) {
42294241 return false;
42304242 }