nx10 / httpgd

Asynchronous http server graphics device for R.
https://nx10.github.io/httpgd
GNU General Public License v2.0
368 stars 19 forks source link

Certain plots crash R: "address (nil), cause 'memory not mapped'" because of "dev.capabilities" #119

Closed mirojantti closed 1 year ago

mirojantti commented 1 year ago

Hey @nx10, great work on this package! Unfortunately, I've encountered an issue with it that makes it unusable for me. This package is essential when using VSCode for R, so I'd be more than happy if this issue was solved.

Calling the dev.capabilities function after starting httpgd with hgd crashes the R session:

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
> dev.capabilities()
$semiTransparency
[1] TRUE

$transparentBackground
[1] "semi"

$rasterImage
[1] "yes"

$capture
[1] TRUE

$locator
[1] TRUE

$events
[1] "MouseDown" "MouseMove" "MouseUp"   "Keybd"    

$patterns
[1] "LinearGradient" "RadialGradient" "TilingPattern" 

$clippingPaths
[1] TRUE

$masks
[1] "alpha"

$compositing
 [1] "multiply"    "screen"      "overlay"     "darken"      "lighten"    
 [6] "color.dodge" "color.burn"  "hard.light"  "soft.light"  "difference" 
[11] "exclusion"   "clear"       "source"      "over"        "in"         
[16] "out"         "atop"        "dest"        "dest.over"   "dest.in"    
[21] "dest.out"    "dest.atop"   "xor"         "add"         "saturate"   

$transformations
[1] TRUE

$paths
[1] TRUE

> httpgd::hgd()
httpgd server running at:
  http://127.0.0.1:45687/live?token=G4tLbeFV
> dev.capabilities()

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: dev.capabilities()

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: 

As an example where this issue arises, here's an attempt at plotting missing data patterns using the MICE-package:

> httpgd::hgd()
httpgd server running at:
  http://127.0.0.1:58519/live?token=ZDUw8arQ
> mice::md.pattern(datasets::airquality)

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: grDevices::dev.capabilities("semiTransparency")
 2: supports.transparent()
 3: mdc(1)
 4: ifelse(R[nrow(R):1, ], mdc(1), mdc(2))
 5: mice::md.pattern(datasets::airquality)

Please let me know what kind of further information you require. I'm using Ubuntu 22.04, but I'm having the same error in Windows 10 too.

nx10 commented 1 year ago

Thanks for the bug report! This was a new bug caused by R 4.2 handling capability reporting differently. Its now fixed in the development version:

remotes::install_github("nx10/httpgd")

image

Technical details: