[R] rgl: exporting to pdf or png does not work

Gaspard Lequeux Gaspard.Lequeux.at at biomath.ugent.be
Thu Aug 24 22:34:25 CEST 2006


On Thu, 24 Aug 2006, Duncan Murdoch wrote:

> On 8/24/2006 11:19 AM, Gaspard Lequeux wrote:
>> On Wed, 23 Aug 2006, Duncan Murdoch wrote:
>>> On 8/23/2006 5:15 PM, Gaspard Lequeux wrote:
>>>> When exporting a image from rgl, the following error is encountered:
>>>>> rgl.postscript('testing.pdf', fmt="pdf")
>>>> RGL: ERROR: can't bind glx context to window
>>>> RGL: ERROR: can't bind glx context to window
>>>> Warning messages:
>>>> 1: X11 protocol error: GLXBadContextState
>>>> 2: X11 protocol error: GLXBadContextState
>>>> The pdf file is created and is readable, but all the labels are gone.
>>>> Taking a snapshot (to png) gives 'failed' and no file is created.
>>>> Version of rgl used: 0.67-2 (2006-07-11)
>>>> Version of R used: R 2.3.1; i486-pc-linux-gnu; 2006-07-13 01:31:16;
>>>> Running Debian GNU/Linux testing (Etch).
>>> That looks like an X11 error to me, not something that I'm very likely
>>> to be able to fix.  If you can debug the error, it would be helpful.
>> Actually after upgrading everything (debian testing (etch)) and restarting
>> X, I didn't get that error anymore. It was worse: R crashed:
>>> library(rgl);triangles3d(c(1,,2,3),c(1,2,4),c(1,3,5));rgl.postscript('testing.pdf','pdf')
>> X Error of failed request:  GLXBadContextState
>>    Major opcode of failed request:  142 (GLX)
>>    Minor opcode of failed request:  5 (X_GLXMakeCurrent)
>>    Serial number of failed request:  85
>>    Current serial number in output stream:  85
>> glequeux at toidi:~/seqanal$
>> I downloaded the source package (debian testing (etch), rgl-0.67-2).
>> In rgl-0.67-2/src/ I changed the following files:
>> rglview.cpp, around line 587. Commenting the function call gl2psBeginPage
>> removed the crash (but also no pdf output...)
>> I enabled this function again and went to gl2ps.c, to the function
>> gl2psBeginPage. At the end of that function, around line 4426, commenting
>> out the line
>> glRenderMode(GL_FEEDBACK);
>> removes the R crash, but of course still no pdf output (well, only the
>> background).
>> GL_FEEDBACK is defined in /usr/include/GL/gl.h as:
>> /* Render Mode */
>> #define GL_FEEDBACK				0x1C01
>> #define GL_RENDER				0x1C00
>> #define GL_SELECT				0x1C02
>> Trying glRenderMode(GL_RENDER) removed the crash, but still only the
>> background in the pdf.
>> If someone has some suggestions about what to do next...
> gl2ps is a separate project, whose source has been included into rgl.
> You can see the gl2ps project page at http://www.geuz.org/gl2ps/.
> We're using version 1.2.2, which is a couple of years old.  The current
> stable release of gl2ps is 1.3.1.  It might fix your problem.
> I don't know if we modified gl2ps.c or gl2ps.h when they were included,
> but they haven't been modified since.  (Daniel put them in, based on a
> patch from Albrecht Gebhardt, according to the log.)
> It would be helpful to know:
> 1.  Is the rgl source identical to 1.2.2?

Yes. The version of gl2ps in rgl is identical to gl2ps version 1.2.2.

> 2.  Does rgl work if 1.3.1 is dropped in instead?


In version 1.3.1:

#define GL2PS_PS  0
#define GL2PS_EPS 1
#define GL2PS_TEX 2
#define GL2PS_PDF 3
#define GL2PS_SVG 4
#define GL2PS_PGF 5

while in version 1.2.2:

#define GL2PS_PS  1
#define GL2PS_EPS 2
#define GL2PS_TEX 3
#define GL2PS_PDF 4

Thus rgl.postscript('probeer.pdf','tex') should be used to generate a pdf. 
The pdf has still no characters (axes annotations).

In R/enum.R

The last line (line 54)

rgl.enum (postscripttype, ps=1, eps=2, tex=3, pdf=4)

should be

rgl.enum (postscripttype, ps=0, eps=1, tex=2, pdf=3)

and mayebe add svg and pgf...

> 3.  Does 1.3.1 fix the bug you're seeing?

No. Same error.

The error occurs also on ubuntu dapper. On that ubuntu machine, when 
installing the libgl1-mesa-swrast, the packages libgl1-mesa 
libgl1-mesa-dri and x-window-system-core are removed. rgl.postscript 
doesn't produce any errors anymore, the pdf is created but no text (axes 
decorations) is written to the pdf.

On debian testing, libgl1-mesa-swx11 can be installed. This removes the 
follwing packages:

freeglut3-dev libgl1-mesa-dev libgl1-mesa-dri libgl1-mesa-glx 
libglitz-glx1-dev libglitz1-dev libglu1-mesa-dev libglui-dev libglut3-dev 
x-window-system-core xlibmesa-gl-dev xorg

but R doesn't crash anymore and the figure is written to file (still 
without axes annotations).

Reinstal libgl1-mesa-glx removes libgl1-mesa-swx11 and the R crash 

So it seems the bug is really triggered by libgl1-mesa. I filled in a bug 
report for the debian package libgl1-mesa-glx.

> I'll look into these at some point, but probably not this week.

Thanks. No hurry however, as I can still use the classical screenshots. 
The figures will probable not have to be published, as the expected 
results are not attained.


More information about the R-help mailing list