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
37 changes: 21 additions & 16 deletions src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,23 @@ inline QLocale inputLocale() {

namespace mixxx {

CoreServices::CoreServices(const CmdlineArgs& args)
CoreServices::CoreServices(const CmdlineArgs& args, QApplication* pApp)
: m_runtime_timer(QLatin1String("CoreServices::runtime")),
m_cmdlineArgs(args) {
m_runtime_timer.start();
mixxx::Time::start();
ScopedTimer t("CoreServices::CoreServices");
// All this here is running without without start up screen
// Defere long initialisations to CoreServices::initialize() which is
// called after the GUI is initalized
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();
}

Expand All @@ -128,11 +141,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 @@ -142,6 +151,10 @@ void CoreServices::initialize(QApplication* pApp) {
m_cmdlineArgs.getLogLevel(),
m_cmdlineArgs.getLogFlushLevel(),
logFlags);
}

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

VERIFY_OR_DEBUG_ASSERT(SoundSourceProxy::registerProviders()) {
qCritical() << "Failed to register any SoundSource providers";
Expand All @@ -150,23 +163,15 @@ 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
if (pApp->platformName() == QLatin1String("xcb")) {
for (auto i = 0; i < NUM_HANDLERS; ++i) {
XESetWireToError(QX11Info::display(), i, &__xErrorHandler);
}
}
#else
Q_UNUSED(pApp);
#endif

UserSettingsPointer pConfig = m_pSettingsManager->settings();
Expand Down
5 changes: 4 additions & 1 deletion src/coreservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class CoreServices : public QObject {
Q_OBJECT

public:
CoreServices(const CmdlineArgs& args);
CoreServices(const CmdlineArgs& args, QApplication* pApp);
~CoreServices();

/// The secondary long run which should be called after displaying the start up screen
void initialize(QApplication* pApp);
void shutdown();

Expand Down Expand Up @@ -119,6 +120,8 @@ class CoreServices : public QObject {
bool initializeDatabase();
void initializeKeyboard();
void initializeSettings();
void initializeScreensaverManager();
void initializeLogging();

std::shared_ptr<SettingsManager> m_pSettingsManager;
std::shared_ptr<mixxx::ControlIndicatorTimer> m_pControlIndicatorTimer;
Expand Down
12 changes: 6 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ namespace {
constexpr int kFatalErrorOnStartupExitCode = 1;
constexpr int kParseCmdlineArgsErrorExitCode = 2;

int runMixxx(MixxxApplication* app, const CmdlineArgs& args) {
const auto pCoreServices = std::make_shared<mixxx::CoreServices>(args);
int runMixxx(MixxxApplication* pApp, const CmdlineArgs& args) {
const auto pCoreServices = std::make_shared<mixxx::CoreServices>(args, pApp);

MixxxMainWindow mainWindow(app, pCoreServices);
app->installEventFilter(&mainWindow);
MixxxMainWindow mainWindow(pApp, pCoreServices);
pApp->installEventFilter(&mainWindow);

QObject::connect(pCoreServices.get(),
&mixxx::CoreServices::initializationProgressUpdate,
&mainWindow,
&MixxxMainWindow::initializationProgressUpdate);
pCoreServices->initialize(app);
pCoreServices->initialize(pApp);
mainWindow.initialize();

// If startup produced a fatal error, then don't even start the
Expand All @@ -44,7 +44,7 @@ int runMixxx(MixxxApplication* app, const CmdlineArgs& args) {
mainWindow.show();

qDebug() << "Running Mixxx";
return app->exec();
return pApp->exec();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/coreservicestest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_F(CoreServicesTest, DISABLED_TestInitialization) {
char* argv[] = {progName, safeMode};
cmdlineArgs.parse(argc, argv);

const auto pCoreServices = std::make_unique<mixxx::CoreServices>(cmdlineArgs);
const auto pCoreServices = std::make_unique<mixxx::CoreServices>(cmdlineArgs, application());
pCoreServices->initialize(application());

EXPECT_NE(pCoreServices->getControllerManager(), nullptr);
Expand Down