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.
Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all
Unified · Split
| @@ -724,7 +724,7 @@ extern DisplayPluginList getDisplayPlugins(); · 723 unmodified lines | ||
| 724 | 724 | extern InputPluginList getInputPlugins(); |
| 725 | 725 | extern void saveInputPluginSettings(const InputPluginList& plugins); |
| 726 | 726 | |
| 727 | −bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, bool runningMarkerExisted) { | |
| 727 | +bool setupEssentials(const QCommandLineParser& parser, bool runningMarkerExisted) { | |
| 728 | 728 | qInstallMessageHandler(messageHandler); |
| 729 | 729 | |
| 730 | 730 | |
| @@ -743,6 +743,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 12 unmodified lines | ||
| 743 | 743 | |
| 744 | 744 | bool previousSessionCrashed { false }; |
| 745 | 745 | if (!inTestMode) { |
| 746 | + // TODO: FIX | |
| 746 | 747 | previousSessionCrashed = CrashRecoveryHandler::checkForResetSettings(runningMarkerExisted, suppressPrompt); |
| 747 | 748 | } |
| 748 | 749 | |
| @@ -764,6 +765,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 15 unmodified lines | ||
| 764 | 765 | } |
| 765 | 766 | |
| 766 | 767 | // Tell the plugin manager about our statically linked plugins |
| 768 | + DependencyManager::set<PathUtils>(); | |
| 767 | 769 | DependencyManager::set<ScriptInitializers>(); |
| 768 | 770 | DependencyManager::set<PluginManager>(); |
| 769 | 771 | auto pluginManager = PluginManager::getInstance(); |
| @@ -777,6 +779,7 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b · 7 unmodified lines | ||
| 777 | 779 | oculusPlatform->init(); |
| 778 | 780 | } |
| 779 | 781 | |
| 782 | + | |
| 780 | 783 | PROFILE_SET_THREAD_NAME("Main Thread"); |
| 781 | 784 | |
| 782 | 785 | #if defined(Q_OS_WIN) |
| @@ -993,8 +996,7 @@ bool Application::initMenu() { · 210 unmodified lines | ||
| 993 | 996 | Application::Application( |
| 994 | 997 | int& argc, char** argv, |
| 995 | 998 | const QCommandLineParser& parser, |
| 996 | − QElapsedTimer& startupTimer, | |
| 997 | − bool runningMarkerExisted | |
| 999 | + QElapsedTimer& startupTimer | |
| 998 | 1000 | ) : |
| 999 | 1001 | QApplication(argc, argv), |
| 1000 | 1002 | _window(new MainWindow(desktop())), |
| @@ -1004,7 +1006,7 @@ Application::Application( · 3 unmodified lines | ||
| 1004 | 1006 | #ifndef Q_OS_ANDROID |
| 1005 | 1007 | _logger(new FileLogger(this)), |
| 1006 | 1008 | #endif |
| 1007 | − _previousSessionCrashed(setupEssentials(argc, argv, parser, runningMarkerExisted)), | |
| 1009 | + _previousSessionCrashed(setupEssentials(parser, false)), | |
| 1008 | 1010 | _entitySimulation(std::make_shared<PhysicalEntitySimulation>()), |
| 1009 | 1011 | _physicsEngine(std::make_shared<PhysicsEngine>(Vectors::ZERO)), |
| 1010 | 1012 | _entityClipboard(std::make_shared<EntityTree>()), |
| @@ -1032,12 +1034,22 @@ Application::Application( · 21 unmodified lines | ||
| 1032 | 1034 | _snapshotSound(nullptr), |
| 1033 | 1035 | _sampleSound(nullptr) |
| 1034 | 1036 | { |
| 1035 | − auto steamClient = PluginManager::getInstance()->getSteamClientPlugin(); | |
| 1036 | − setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning())); | |
| 1037 | 1037 | setProperty(hifi::properties::CRASHED, _previousSessionCrashed); |
| 1038 | 1038 | |
| 1039 | 1039 | LogHandler::getInstance().moveToThread(thread()); |
| 1040 | 1040 | 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 | + | |
| 1041 | 1053 | |
| 1042 | 1054 | { |
| 1043 | 1055 | if (parser.isSet("testScript")) { |
| @@ -2375,7 +2387,7 @@ Application::Application( · 1331 unmodified lines | ||
| 2375 | 2387 | |
| 2376 | 2388 | connect(this, &Application::applicationStateChanged, this, &Application::activeChanged); |
| 2377 | 2389 | 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); | |
| 2379 | 2391 | |
| 2380 | 2392 | EntityTreeRenderer::setEntitiesShouldFadeFunction([this]() { |
| 2381 | 2393 | SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer); |
| @@ -4201,7 +4213,9 @@ bool Application::handleFileOpenEvent(QFileOpenEvent* fileEvent) { · 1819 unmodified lines | ||
| 4201 | 4213 | } |
| 4202 | 4214 | |
| 4203 | 4215 | 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 | |
| 4205 | 4219 | PROFILE_RANGE_IF_LONGER(app, "notify", 2) |
| 4206 | 4220 | return QApplication::notify(object, event); |
| 4207 | 4221 | } |
| @@ -8762,7 +8776,11 @@ void Application::sendLambdaEvent(const std::function<void()>& f) { · 4554 unmodified lines | ||
| 8762 | 8776 | } |
| 8763 | 8777 | } |
| 8764 | 8778 | |
| 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 | + | |
| 8766 | 8784 | if (parser.isSet("display")) { |
| 8767 | 8785 | auto preferredDisplays = parser.value("display").split(',', Qt::SkipEmptyParts); |
| 8768 | 8786 | qInfo() << "Setting prefered display plugins:" << preferredDisplays; |
| @@ -8780,6 +8798,7 @@ void Application::initPlugins(const QCommandLineParser& parser) { · 11 unmodified lines | ||
| 8780 | 8798 | qInfo() << "Disabling following input plugins:" << disabledInputs; |
| 8781 | 8799 | PluginManager::getInstance()->disableInputs(disabledInputs); |
| 8782 | 8800 | } |
| 8801 | + | |
| 8783 | 8802 | } |
| 8784 | 8803 | |
| 8785 | 8804 | void Application::shutdownPlugins() { |