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

hack around Xlib deadlock #1923

Merged
merged 6 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ addons:
- protobuf-compiler
- qt5-default
- qtscript5-dev
- libqt5x11extras5-dev
- scons
- vamp-plugin-sdk
- qtkeychain-dev
Expand Down
3 changes: 3 additions & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ def enabled_modules(build):
'QtTest',
'QtXml',
]

if qt5:
if build.platform_is_linux:
build.env.Append(LIBS = 'Qt5X11Extras')
qt_modules.extend([
# Keep alphabetized.
'QtConcurrent',
Expand Down
46 changes: 40 additions & 6 deletions src/mixxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,41 @@
#include "preferences/dialog/dlgprefmodplug.h"
#endif

#if defined(Q_OS_LINUX)
#include <QtX11Extras/QX11Info>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>
// Xlibint.h predates C++ and defines macros which conflict
// with references to std::max and std::min
#undef max
#undef min
#endif

namespace {

const mixxx::Logger kLogger("MixxxMainWindow");

// hack around https://gitlab.freedesktop.org/xorg/lib/libx11/issues/25
// https://bugs.launchpad.net/mixxx/+bug/1805559
#if defined(Q_OS_LINUX)
typedef Bool (*WireToErrorType)(Display*, XErrorEvent*, xError*);

const int NUM_HANDLERS = 256;
WireToErrorType __oldHandlers[NUM_HANDLERS] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't get the magic behind this array. Which unknown side effect sets the elements to a value other than 0? Currently the error interceptor does nothing except ignoring and dropping all incoming extension errors. This can be implemented in a much simpler way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, neither do I, nor do I understand the magic number 256. I've never worked with X11 code before, much less understand X's internals. I just copied and pasted from https://bugs.freedesktop.org/show_bug.cgi?id=59361#c4 and got it to build.

Copy link
Contributor

Choose a reason for hiding this comment

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

256 because the error code is an unsigned char with values ranging from 0 to 255. But all slots are initialized with 0 (= nullptr) and are never updated.


Bool __xErrorHandler(Display* display, XErrorEvent* event, xError* error) {
// Call any previous handler first in case it needs to do real work.
auto code = static_cast<int>(event->error_code);
if (__oldHandlers[code] != NULL) {
__oldHandlers[code](display, event, error);
}

// Always return false so the error does not get passed to the normal
// application defined handler.
return False;
}
#endif

} // anonymous namespace

// static
Expand Down Expand Up @@ -150,12 +181,6 @@ MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
setCentralWidget(m_pWidgetParent);

show();
#if defined(Q_WS_X11)
// In asynchronous X11, the window will be mapped to screen
// some time after being asked to show itself on the screen.
extern void qt_x11_wait_for_window_manager(QWidget *mainWin);
qt_x11_wait_for_window_manager(this);
#endif
pApp->processEvents();

initialize(pApp, args);
Expand All @@ -169,6 +194,15 @@ MixxxMainWindow::~MixxxMainWindow() {
void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {
ScopedTimer t("MixxxMainWindow::initialize");

#if defined(Q_OS_LINUX)
// XESetWireToError will segfault if running as a Wayland client
if (pApp->platformName() == QStringLiteral("xcb")) {
for (auto i = 0; i < NUM_HANDLERS; ++i) {
XESetWireToError(QX11Info::display(), i, &__xErrorHandler);
}
}
#endif

UserSettingsPointer pConfig = m_pSettingsManager->settings();

Sandbox::initialize(QDir(pConfig->getSettingsPath()).filePath("sandbox.cfg"));
Expand Down