Saturday, March 03, 2007

MATLAB xcb_xlib_lock Assertion in Feisty


Important Update: With the last update of Feisty Fawn (Herd 5 and up) using this work around will make your KDE unusable!. KDM will start but suddenly disappear leaving a black screen with a cursor blinking at the top left. From the console startx will run ok but with no means to start KDE from within it.

The good news is that with the new updates Matlab works out of the box without need of this work around at all. If you made a copy of the libxcb-xlib.so.0.0.0 file simply restore it and your system will be back on shape. Make sure to install the newest version of libxcb-xlib and Matlab should work without problems... It does on my system.


After I installed Feisty on my machine I installed and tried Matlab and for my unpleasant surprise Matlab started crashing every time I opened a new window. For example the command "plot" that opens a new window would crash Matlab with the following assertion:

MATLAB: xcb_xlib.c:41: xcb_xlib_lock: Assertion `!c->xlib.lock' failed.
Aborted


My only option at the moment was to keep using Edgy until Mathworks fixes the bug in any of their next releases (something that may never happen). But after I tested Feisty I really did not want to give up on it and as a good Linux user I asked the community and as always got a better solution.

It happens that this xcb_xlib_lock assertion bug is common not only in Matlab but in several other applications used in (K)Ubuntu. Reading the Ubuntu forums (see here and here) you can see that the problem has been addressed in two different ways:

One is to download the libx11-6_1.0.3-5_i386.deb package that comes with Edgy and force a downgrade with:

sudo dpkg --force-all --install libx11-6_1.0.3-5_i386.deb

I have not tried this method but some people report it works without problems.

The second method (the one I used) is to download and modify the source code so the Assertion check is bypassed. This sounds difficult but thanks to the Debian package management system it can be done in a few steps.

First download the source code and all build dependencies in a temp directory (i.e. ~/tmp):

apt-get source libxcb-xlib0
sudo apt-get build-dep libxcb-xlib0

Change to the source directory and edit the libxcb-1.0

cd libxcb-1.0
vi src/xcb_xlib.c

Feel free to use your favorite text editor (I like vim) and comment the following two lines:

assert(!c->xlib.lock); change to: //assert(!c->xlib.lock);

assert(c->xlib.lock); change to: //assert(c->xlib.lock);

This source file has few code lines so finding the lines to comment should be no problem at all. To comment them simple add "//" at the start of the line or you can delete them all together.

Next build the library:

./configure
make

If the configure script fails make sure you have the build-essential packages installed. If the make command finishes without any errors LOG OUT the X session and change to a console terminal. If you do not log out the next step is gonna crash you X very hard. To change to a console terminal press ++ (after you have logged out!) and to return back to the X console press ++.

cp /usr/lib/libxcb-xlib.so.0.0.0 /usr/lib/libxcb-xlib.so.0.0.0.orig
cp ~/tmp/libxcb-1.0/src/.libs/libxcb-xlib.so.0.0.0 /usr/lib

Replace ~/tmp with the temporary directory where you downloaded and compiled the source code. Finally restart your X11 server (reboot the PC to be sure) and now Matlab runs flawlessly on Feisty. You can also delete the tmp directory if you want.

I must mention that this bug is caused by bad programming practices when using the Xlib libraries and not a problem in Xlib itself. Read here and here for more information.

No comments:

Post a Comment