Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CoreServices initalisation order #4058

Merged
merged 13 commits into from
Aug 1, 2021
Merged
36 changes: 22 additions & 14 deletions src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ void CoreServices::initializeSettings() {
m_pSettingsManager = std::make_unique<SettingsManager>(settingsPath);
}

void CoreServices::initialize(QApplication* pApp) {
m_runtime_timer.start();
mixxx::Time::start();
ScopedTimer t("CoreServices::initialize");

void CoreServices::initializeLogging() {
mixxx::LogFlags logFlags = mixxx::LogFlag::LogToFile;
if (m_cmdlineArgs.getDebugAssertBreak()) {
logFlags.setFlag(mixxx::LogFlag::DebugAssertBreak);
Expand All @@ -136,6 +132,25 @@ void CoreServices::initialize(QApplication* pApp) {
m_cmdlineArgs.getLogLevel(),
m_cmdlineArgs.getLogFlushLevel(),
logFlags);
}

void CoreServices::preInitialize(QApplication* pApp) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method really necessary? Couldn't we just make it part of the CoreServices constructor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any need to create the CoreServices object before creating a QApplication? If not, we should move this into the constructor. Less possibilities to use this class wrong or miss an initialization step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There does not seem to be a purpose for this method. Move the code directly into the constructor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just documentation support.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this makes the code more readable; it makes me wonder why the function exists. I think it would be better to move the code into the constructor and add a comment: "These need to be initialized before the GUI. They are fast to initialize. Everything else is deferred to the initialize method so the GUI can show the progress."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't to bike-shed, but

  • it only contains the body of the constructor, which now contains just this single invocation and
  • the method is public although it doesn't need to be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is private.

ScopedTimer t("CoreServices::preInitialize");
initializeSettings();
initializeLogging();
// Only record stats in developer mode.
if (m_cmdlineArgs.getDeveloper()) {
StatsManager::createInstance();
}
mixxx::Translations::initializeTranslations(
m_pSettingsManager->settings(), pApp, m_cmdlineArgs.getLocale());
initializeKeyboard();
}

void CoreServices::initialize(QApplication* pApp) {
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
m_runtime_timer.start();
mixxx::Time::start();
ScopedTimer t("CoreServices::initialize");

VERIFY_OR_DEBUG_ASSERT(SoundSourceProxy::registerProviders()) {
qCritical() << "Failed to register any SoundSource providers";
Expand All @@ -144,15 +159,6 @@ void CoreServices::initialize(QApplication* pApp) {

VersionStore::logBuildDetails();

// Only record stats in developer mode.
if (m_cmdlineArgs.getDeveloper()) {
StatsManager::createInstance();
}

initializeKeyboard();

mixxx::Translations::initializeTranslations(
m_pSettingsManager->settings(), pApp, m_cmdlineArgs.getLocale());

#if defined(Q_OS_LINUX)
// XESetWireToError will segfault if running as a Wayland client
Expand All @@ -161,6 +167,8 @@ void CoreServices::initialize(QApplication* pApp) {
XESetWireToError(QX11Info::display(), i, &__xErrorHandler);
}
}
#else
Q_UNUSED(pApp);
#endif

UserSettingsPointer pConfig = m_pSettingsManager->settings();
Expand Down
8 changes: 6 additions & 2 deletions src/coreservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ class CoreServices : public QObject {
~CoreServices() = default;

void initializeSettings();
// FIXME: should be private, but WMainMenuBar needs it initialized early
void initializeKeyboard();
void initializeLogging();

// The short first run that is done without start up screen
void preInitialize(QApplication* pApp);
// The secondary long run which should be called after displaying the start up screen
void initialize(QApplication* pApp);
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
void shutdown();

Expand Down Expand Up @@ -112,7 +116,7 @@ class CoreServices : public QObject {
std::shared_ptr<SettingsManager> m_pSettingsManager;
std::shared_ptr<EffectsManager> m_pEffectsManager;
// owned by EffectsManager
LV2Backend* m_pLV2Backend;
LV2Backend* m_pLV2Backend{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change, please remove from this PR

std::shared_ptr<EngineMaster> m_pEngine;
std::shared_ptr<SoundManager> m_pSoundManager;
std::shared_ptr<PlayerManager> m_pPlayerManager;
Expand Down
3 changes: 1 addition & 2 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ MixxxMainWindow::MixxxMainWindow(
m_toolTipsCfg(mixxx::TooltipsPreference::TOOLTIPS_ON) {
DEBUG_ASSERT(pApp);
DEBUG_ASSERT(pCoreServices);
m_pCoreServices->initializeSettings();
m_pCoreServices->initializeKeyboard();
m_pCoreServices->preInitialize(pApp);
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
// These depend on the settings
createMenuBar();
m_pMenuBar->hide();
Expand Down