[R-SIG-Mac] more rgl problems

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Feb 18 21:20:03 CET 2021


I've made some progress on this, but I don't know how to fix it properly.

What's happening is that rgl is trying to open the new window that 
open3d() asks for.  It gets most of the way through that operation, then 
calls glXMakeCurrent, which associates the OpenGL context with that 
window.  That call fails, but without generating any of the documented 
errors:  it just fails, triggering an X11 error handler with error code 
0 (which typically means no error).

In the released versions of rgl, that failure leads to a segfault, 
because I wasn't doing enough error checking.  I've fixed the segfault, 
but I'm still getting the error (in fact I'm getting it a lot more than 
I used to; not sure if it's my debugging code causing that), and after I 
get the error reported on screen, the new rgl window opens but doesn't 
work to display anything.

I think it's probably something wrong in the rgl initialization code; 
running this:

   plot(1:10, col=7)
   library(rgl)
   open3d()

is fine, whereas this:

   library(rgl)
   plot(1:10, col=7)
   open3d()

is always failing for me.  Or possibly this is an Xquartz bug, maybe a 
leftover from when I installed the beta.

I'd guess what's happening is that calling quartz() invalidates part of 
the initialization done by rgl.init(), but I don't know what part yet. 
I do want to call rgl.init() when loading rgl, because it might fail, 
and then I can drop back to the off-screen drawing.  It's too late to do 
that later.

A workaround that works for me is for the .onload() function in rgl to 
execute

  dev.new()
  dev.off()

before calling rgl.init(). It is less irritating than you might guess, 
because the window doesn't have time to appear before being destroyed, 
but I still don't like it.   I'll try it out a bit, and then push it to 
Github for others to test.

Duncan Murdoch


On 18/02/2021 6:28 a.m., Duncan Murdoch wrote:
> I can reproduce this on a Catalina machine, working in R from the terminal.
> 
> This definitely looks similar to the problem that
> rgl::setGraphicsDelay() was designed to solve, but even adding a 10
> second delay doesn't help.  I get a slightly different message than you:
> 
>   > open3d()
> error: xp_attach_gl_context returned: 2
> 
>    *** caught segfault ***
> address 0x18, cause 'memory not mapped'
> 
> but that might just be a different way of reporting the same underlying
> issue.
> 
> It's clearly some kind of interaction between the Quartz device and rgl.
>    I'll see if I can track it down.
> 
> Duncan Murdoch
> 
> On 17/02/2021 7:36 p.m., Richard M. Heiberger wrote:
>> This is repeatable when the lines are all pasted in at once.
>> The example works if I allow some time delay between lines.
>>
>> This is might be a relative of the one from a few months ago.
>> But this message is about invalid permissions.
>> =====
>>
>> R version 4.0.4 RC (2021-02-12 r79998) -- "Lost Library Book"
>> Copyright (C) 2021 The R Foundation for Statistical Computing
>> Platform: x86_64-apple-darwin17.0 (64-bit)
>>
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>>
>>     Natural language support but running in an English locale
>>
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information and
>> 'citation()' on how to cite R or R packages in publications.
>>
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>> 'help.start()' for an HTML browser interface to help.
>> Type 'q()' to quit R.
>>
>>> setwd('/Users/rmh/Rwd/')
>>> library(rgl)
>>> x <- matrix(1:3, 1,3)
>>> plot(1:10, col=7)
>>> open3d()
>> error: xp_attach_gl_context returned: 2
>>
>>    *** caught segfault ***
>> address 0x18, cause 'invalid permissions'
>>
>> Traceback:
>>    1: rgl.open(useNULL)
>>    2: open3d()
>>
>> Possible actions:
>> 1: abort (with core dump, if enabled)
>> 2: normal R exit
>> 3: exit R without saving workspace
>> 4: exit R saving workspace
>> Selection:
>>
>>
>> ====
>> MacBookAir with the M1 chip using the regular intel version of R from CRAN.
>> Big Sur 11.2.1.
>> The plot(1:10), col=7) ## went by default to the quartz() device.
>>
>>
>> I repeated this about 5 times in ESS, and then once in Terminal.
>>
>> Let me know if you need more information.
>>
>



More information about the R-SIG-Mac mailing list