A few months ago, an update in MacPorts sufficiently changed the libraries that were used by The Gimp such that it caused the X11 server (including the Apple bundled X11.app) to crash any time the mouse moved over the "Curves" adjustment window. This affected both the Apple OS X 10.6 (Snow Leopard) and OS X 10.7 (Lion) X11 servers, as well as the XQartz/xorg-server upto and including version 1.11.2 (which is newer than the xorg-server, stable, port even as of this writing; X.Org XServer 1.11 was released on 2011-08-26). Since the "Curves" feature of The Gimp is something I want to use often when editing photos, it was rather inconvenient (some changes can be achievd with "Levels", but it's a much more primitive tool).

The cause was eventually tracked down to a NULL pointer appearing where the X11 server didn't expect, which is only an issue when running the server in "Rootless" mode -- something which the OS X deployment does, since (unlike, eg, Linux or FreeBSD), the main GUI desktop uses a different graphical environment (Quartz -- hence XQuartz). A fix was created which added an additional check for the NULL value (and skipped trying to use it, if the value was NULL), which was committed to Jeremy Huddleston (jeremyhu)'s xserver git tree, on the master branch, on 2011-11-18. (The change is to miext/rootless/rootlessScreen.c around line 247.)

Jeremy Huddleston ("jeremyhu") noted that the fix would appear on the xorg-server-devel MacPort once it was merged into the main xorg-server development tree (and then eventually after that in the xorg-server stable MacPort). The master X.Org XServer GIT repository did pick up this change on 2011-11-18, just before the commit (on 2011-11-20) that created the 1.11.99.1 test version, which is the X.Org Xserver GIT master revision built by the xorg-xserver-devel MacPort at this time.

It seems unlikely to make it into the Apple OS X X11.app application, as an OS update, in the near future given that it's only a stability update for a specific combination of circumstances in a single application at this time -- even if it's a combination that is particularly useful. So I decided to change my X11 server (on Snow Leopard) to the xorg-server-devel macport, since (as above) it appears it will include the necessary fix. (The latest XQuartz release (2011-11-04) seems to be a little bit old to include the fix; but possibly there's also a development build of that which does include the fix; Jeremy Huddleston maintains both XQuartz and xorg-xserver(-devel).)

The process, assuming MacPorts is already installed, is:

  • sudo port selfupdate

  • sudo port install xorg-xserver-devel (which will install quite a few dependencies, including a bunch of fonts and font handling libraries, so make sure you've got a reasonable amount of time and disk space available)

The result of that is to install a more up to date X Server in parallel with Apple's X server (installs in /Applications/MacPorts/X11.app and /opt/local/bin), which you can run instead of Apple's one (installed in /Application/Utilities/X11.app and /usr/X11/bin).

Immediately after building the resulting XServer can be tested by (a) quitting the Apple OS X X11.app, and (b) starting /Applications/MacPorts/X11.app manually, and then running the X application (eg, gimp) from within that X server -- but it will not be used automatically (eg, when starting applications from outside X11.app). You can verify that the correct XServer is running by looking at X11->About X11, and also by looking at the logo of the XServer. Having done that, it is then possible to start gimp from an xterm (eg, Applications->Terminal within X11.app, then run "gimp &"), create a new image, and then use the Curves tool and verify that the X Server doesn't crash. Thus verifying that the fix works. (Running gimp from, eg, Terminal.app -- without having logged out/logged back in again (see below) -- will result in launching the built in Apple OS X XServer, which will crash with the same test.)

Providing that looks fine, the default (as a result of installing the xinit MacPort) after logging out and logging in will be to trigger the MacPorts xorg-xserver-devel X Server to auto-start instead of the Apple OS X one. This is managed by the /Library/LaunchAgents/org.macports.startx.plist launchctl hook (ie, to launch that X Server on demand), which is installed as part of the xinit MacPort. You can check that it is active with:

launchctl list | grep macports

which should list:

62052   -   org.macports.startx

(probably with a different process ID number in the first column) if it is active.

If necessary the auto-start of the MacPorts X Server can be disabled with:

lauchctl unload -w /Library/LaunchAgents/org.macports.startx.plist 

(as described in this thread). The "unload -w" forces it to be disabled, despite how it is already set in the plist file.

Now (after logging out/logging in again -- which took quite a while to clear back to the Desktop), I can use the "Curves" feature of The Gimp again safely. As well as getting the other advantages of 2 years of X Server updates. (Although at the cost of running what is effectively a pre-release version of the X.Org XServer 1.12 -- it's effectively an early release candidate.)

Updated, 2012-03-13: xorg-server and xorg-server-devel have now been updated to 1.12.0 release versions, so I have switched to xorg-server which now includes the relevant fix -- and avoids the need to chase development update versions. Quit the X11 app, then run:

sudo port deactivate xorg-server-devel
sudo port install xorg-server

and after starting a new X11 app (eg, gimp) use "About X11" to verify that the 1.12 version of the X server is running.

Updated, 2012-04-26: After, I think, one of the OS X security updates I found that the Apple supplied X11 server was back to launching by default (and hence gimp was crashing X11 when the curves functionality as used). The fix was to upgrade xinit (which fortunately had an update ready) and that reminded me:

###############################################################################
# To choose MacPorts' X11 as the default server, you must install xorg-server,
# load the LaunchAgent, logout, and log back in.  To load the LaunchAgent,
# please execute the following:
# launchctl load -w /Library/LaunchAgents/org.macports.startx.plist
# 
# This will be remembered across port updates on Snow Leopard and later.
###############################################################################

so in theory the launchctl command may be the only thing required. In practice I found I needed to do:

launchctl unload -w /System/Library/LaunchAgents/org.x.startx.plist
launchctl load -w /Library/LaunchAgents/org.macports.startx.plist

to get the change to stick, otherwise the Apple supplied one seemed to be taking precedence all the time. It's also important not to use sudo when running these, or they will be ignored with a normal login.