# Exporting twice crashes Mathematica on Ubuntu 12.04 with Unity

I'm trying to work out if it's a Mathematica, Ubuntu or setup specific bug. I've asked some colleagues to try it on other Linuxes.

This also crashes on OS X with Mathematica 8.0 and fails with 9.0, so it looks like it could be a Mathematica bug (output on request). It may be an artefact of running on the CLI (my tests on 9.0 so far have had to be via ssh), though the full 8.0 .app crashes, too.

Warning: it may suddenly end your session, so close all other programs and save your work, etc, first.

logMeOut.m

p = ListDensityPlot[Table[RandomReal[], {i, 1, 128}, {j, 1, 128}]];
Export["myPlot.jpg", p, ImageSize -> Scaled[2]]
Export["myPlot.jpg", p, ImageSize -> Scaled[2]]


run it with

$/path/to/MathKernel -noprompt -script logMeOut.m  Interestingly, when I run either of $ strace -f /path/to/MathKernel -noprompt -script logMeOut.m &> mathematicabug.strace


(output on request) or

\$ /path/to/MathKernel -noprompt -script logMeOut.m &> mathematicabug.log


I don't get logged out. The second gives no output.

Per the strace, the library accessed before the crash (it still seg faults) is terminfo (/lib/x86_64-linux-gnu/libtinfo.so.5), so given the above suppresses output, it may be related to that.

Any ideas from a Mathematica rather than system perspective why it doesn't work? System perspectives are also welcome, though maybe don't go here.

-
Amazing. This hung my X and I'm unable to even ssh into the machine (nor use serial console to login). Absolutely didn't expect this... –  Ruslan May 10 '13 at 14:10
Same on Fedora 18. –  b.gatessucks May 10 '13 at 14:23
This looks like a bug in OpenGL drivers. I've tried running this with vesa set as X driver, and MathKernel complains on GLX extension missing, without hanging. And when I renamed /usr/lib/libGL.so.1 and relaunched the command, it just started to eat CPU time. After some time I get loads of RenderBadPicture and BadGC errors in xterm. –  Ruslan May 10 '13 at 14:58

This is definitely a problem in Xorg or multiple drivers. The behavior you describe, i.e. logging out, appears on machine with Intel graphics. If you try this on nVidia machine with nvidia driver, you'll have a hang. Now, you may be lucky to have something in /var/log/Xorg.0.log*. Here's what I have near the end of /var/log/Xorg.0.log.old.

The workaround is to rename /usr/lib/libGL.so.1. In this case I'm not sure the process will ever end, but still it doesn't make your system crash.

As for MacOS X, I think their drivers also have a similar bug.

In fact, it might be that in all these cases Mathematica works in quite a broken way, so it might also have a bug, BUT no app should ever be able to hang or crash X, so firstly this problem should be reported to driver developers.

-
Thank you, that's very helpful. I will definitely investigate this, but it's not an entirely satisfactory answer in that it doesn't explain why Mathematica crashes in a cross-platform way when one does this. I'll wait a bit before marking answered in case someone gives such an explanation. –  Russell Jones May 10 '13 at 15:54
Why it crashes in a cross-platform way may be pretty easy explained by the fact that it uses OpenGL to do some graphic operations in both Linux and MacOS X, so these routines which have bug are being executed on both OSes. In fact, we've not seen whether it crashes on Windows :). But it may well be that it does in Windows too because of some common layer of abstraction from OGL&DX called in a buggy way. –  Ruslan May 10 '13 at 16:02
I get pastebin.com/VUfqkciK . I'll try it a few more times in case I can get anything different. I'll also check the debug symbols as it looks like some things weren't resolved. After that, I guess I'll be off to find the mailing list for the intel Xorg driver. –  Russell Jones May 10 '13 at 16:03
it also crashes on Windows ... –  Rolf Mertig May 10 '13 at 20:00

Indeed, it is a problem with the drivers, in my case triggered by exporting images with high DPI. Apparently, Mathematica allocates large pixmaps when exporting, which reaches the limit of Intel drivers (see https://bugs.freedesktop.org/show_bug.cgi?id=63393 for the bug report). This was also the case for radeon drivers until recently, when the bug was fixed. Perhaps someone should file a bug report for NVidia?

-