History

Initial effort to reorganize the startup code.

This is intended to make things like plugin initialization more sane, and make Qt happier. Qt wants QApplication to start as soon as possible, but our code's attempt to load the entire world in the Application constructor doesn't quite mesh with this. This is an effort to first create Application much earlier, and do as little as possible in the constructor, moving almost all initialization to a later init function. A later stage would be to split the giant mess of init code into more digestible sections that run in some sort of logical order.

Dale Glass committed 3 years ago

Commit 059600e1 parent 85a99873 files · +87 −25Browse files

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

Unified · Split

interface/src/Application.cpp+28−9
@@ -724,7 +724,7 @@ extern DisplayPluginList getDisplayPlugins(); · 723 unmodified lines
724724 extern InputPluginList getInputPlugins();
725725 extern void saveInputPluginSettings(const InputPluginList& plugins);
726726
727−bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, bool runningMarkerExisted) {
727+bool setupEssentials(const QCommandLineParser& parser, bool runningMarkerExisted) {
728728 qInstallMessageHandler(messageHandler);
729729
730730
@@ -743,6 +743,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 12 unmodified lines
743743
744744 bool previousSessionCrashed { false };
745745 if (!inTestMode) {
746+ // TODO: FIX
746747 previousSessionCrashed = CrashRecoveryHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt);
747748 }
748749
@@ -764,6 +765,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 15 unmodified lines
764765 }
765766
766767 // Tell the plugin manager about our statically linked plugins
768+ DependencyManager::set<PathUtils>();
767769 DependencyManager::set<ScriptInitializers>();
768770 DependencyManager::set<PluginManager>();
769771 auto pluginManager = PluginManager::getInstance();
@@ -777,6 +779,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 7 unmodified lines
777779 oculusPlatform->init();
778780 }
779781
782+
780783 PROFILE_SET_THREAD_NAME("Main Thread");
781784
782785 #if defined(Q_OS_WIN)
@@ -993,8 +996,7 @@ bool Application::initMenu() { · 210 unmodified lines
993996 Application::Application(
994997 int& argc, char** argv,
995998 const QCommandLineParser& parser,
996− QElapsedTimer& startupTimer,
997− bool runningMarkerExisted
999+ QElapsedTimer& startupTimer
9981000 ) :
9991001 QApplication(argc, argv),
10001002 _window(new MainWindow(desktop())),
@@ -1004,7 +1006,7 @@ Application::Application( · 3 unmodified lines
10041006 #ifndef Q_OS_ANDROID
10051007 _logger(new FileLogger(this)),
10061008 #endif
1007− _previousSessionCrashed(setupEssentials(argc, argv, parser, runningMarkerExisted)),
1009+ _previousSessionCrashed(setupEssentials(parser, false)),
10081010 _entitySimulation(std::make_shared<PhysicalEntitySimulation>()),
10091011 _physicsEngine(std::make_shared<PhysicsEngine>(Vectors::ZERO)),
10101012 _entityClipboard(std::make_shared<EntityTree>()),
@@ -1032,12 +1034,22 @@ Application::Application( · 21 unmodified lines
10321034 _snapshotSound(nullptr),
10331035 _sampleSound(nullptr)
10341036 {
1035− auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
1036− setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
10371037 setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
10381038
10391039 LogHandler::getInstance().moveToThread(thread());
10401040 LogHandler::getInstance().setupRepeatedMessageFlusher();
1041+}
1042+
1043+void Application::initialize(const QCommandLineParser &parser) {
1044+
1045+ //qCDebug(interfaceapp) << "Setting up essentials";
1046+ //setupEssentials(parser, _previousSessionCrashed);
1047+ qCDebug(interfaceapp) << "Initializing application";
1048+
1049+
1050+ auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
1051+ setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
1052+
10411053
10421054 {
10431055 if (parser.isSet("testScript")) {
@@ -2375,7 +2387,7 @@ Application::Application( · 1331 unmodified lines
23752387
23762388 connect(this, &Application::applicationStateChanged, this, &Application::activeChanged);
23772389 connect(_window, SIGNAL(windowMinimizedChanged(bool)), this, SLOT(windowMinimizedChanged(bool)));
2378− qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0);
2390+ qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)_sessionRunTimer.elapsed() / 1000.0);
23792391
23802392 EntityTreeRenderer::setEntitiesShouldFadeFunction([this]() {
23812393 SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
@@ -4201,7 +4213,9 @@ bool Application::handleFileOpenEvent(QFileOpenEvent* fileEvent) { · 1819 unmodified lines
42014213 }
42024214
42034215 bool Application::notify(QObject * object, QEvent * event) {
4204− if (thread() == QThread::currentThread()) {
4216+ if (thread() == QThread::currentThread() && _profilingInitialized ) {
4217+ // _profilingInitialized gets set once we're reading for profiling.
4218+ // this prevents a deadlock due to profiling not working yet
42054219 PROFILE_RANGE_IF_LONGER(app, "notify", 2)
42064220 return QApplication::notify(object, event);
42074221 }
@@ -8762,7 +8776,11 @@ void Application::sendLambdaEvent(const std::function<void()>& f) { · 4554 unmodified lines
87628776 }
87638777 }
87648778
8765−void Application::initPlugins(const QCommandLineParser& parser) {
8779+void Application::configurePlugins(const QCommandLineParser& parser) {
8780+ // This must be a member function -- PluginManager must exist, and for that
8781+ // QApplication must exist, or it can't find the plugin path, as QCoreApplication:applicationDirPath
8782+ // won't work yet.
8783+
87668784 if (parser.isSet("display")) {
87678785 auto preferredDisplays = parser.value("display").split(',', Qt::SkipEmptyParts);
87688786 qInfo() << "Setting prefered display plugins:" << preferredDisplays;
@@ -8780,6 +8798,7 @@ void Application::initPlugins(const QCommandLineParser& parser) { · 11 unmodified lines
87808798 qInfo() << "Disabling following input plugins:" << disabledInputs;
87818799 PluginManager::getInstance()->disableInputs(disabledInputs);
87828800 }
8801+
87838802 }
87848803
87858804 void Application::shutdownPlugins() {