tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.05k stars 211 forks source link

Rsession frequently crashes with render_snapshot() and plot_3d() #302

Open richardtc opened 9 months ago

richardtc commented 9 months ago

The Rsession within RStudio server frequently crashes with render_snapshot() and plot_3d(). A point is reached where a file (v_mat matrix below) becomes too large to render when using render_snapshot and/or plot_3d. I guess this is related to the cache.

I have increased the resource limits in the Docker container (with installed RStudio Server) and on the host machine:

# rlimit_all()
# $cur
#      as    core     cpu    data   fsize memlock  nofile   nproc   stack 
#     Inf     Inf     Inf     Inf     Inf     Inf    4096     Inf 8388608 
# 
# $max
#      as    core     cpu    data   fsize memlock  nofile   nproc   stack 
#     Inf     Inf     Inf     Inf     Inf     Inf    4096     Inf     Inf

I run the Docker container with the --ulimit memlock=-1:-1 option.

Here is an error example error related to plot_3d:

   Error: rsession: cache resources exhausted `/tmp/RtmpivuAjx/file3e4e2c167.png' @ error/cache.c/OpenPixelCache/4095   

Alternatively, and typically, the session just crashes without any warning message with render_snapshot()

I'm running this code:

v_mat %>%
  sphere_shade(texture = "imhof2") %>%
  plot_3d(v_mat, zscale = 50, theta = 20, zoom = 0.65, fov = 0, phi = 35, windowsize = c(1000, 800))
  Sys.sleep(0.2)
  #render_snapshot()
  render_snapshot("FILENAME9.png", clear = TRUE)

Session info:

> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8   
 [6] LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: Asia/Bangkok
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] unix_1.5.6          rayimage_0.10.0     devtools_2.4.5      usethis_2.2.2       suncalc_0.5.1       gdalUtilities_1.2.5
[7] rayshader_0.36.1    terra_1.7-67       

loaded via a namespace (and not attached):
 [1] xfun_0.41          raster_3.6-26      remotes_2.4.2.1    htmlwidgets_1.6.4  lattice_0.22-5     vctrs_0.6.5        tools_4.3.2       
 [8] generics_0.1.3     parallel_4.3.2     rgl_1.2.9          tibble_3.2.1       proxy_0.4-27       fansi_1.0.6        pkgconfig_2.0.3   
[15] KernSmooth_2.23-22 data.table_1.14.10 lifecycle_1.0.4    stringr_1.5.1      compiler_4.3.2     progress_1.2.3     codetools_0.2-19  
[22] httpuv_1.6.12      htmltools_0.5.7    class_7.3-22       yaml_2.3.8         urlchecker_1.0.1   pillar_1.9.0       later_1.3.1       
[29] crayon_1.5.2       ellipsis_0.3.2     classInt_0.4-10    cachem_1.0.8       magick_2.8.1       sessioninfo_1.2.2  iterators_1.0.14  
[36] foreach_1.5.2      mime_0.12          tidyselect_1.2.0   digest_0.6.33      stringi_1.8.3      sf_1.0-15          dplyr_1.1.4       
[43] purrr_1.0.2        bookdown_0.36      fastmap_1.1.1      grid_4.3.2         cli_3.6.2          magrittr_2.0.3     base64enc_0.1-3   
[50] pkgbuild_1.4.3     utf8_1.2.4         e1071_1.7-14       promises_1.2.1     prettyunits_1.2.0  sp_2.1-2           lubridate_1.9.3   
[57] timechange_0.2.0   rmarkdown_2.25     png_0.1-8          hms_1.1.3          memoise_2.0.1      shiny_1.8.0        evaluate_0.23     
[64] knitr_1.45         doParallel_1.0.17  miniUI_0.1.1.1     profvis_0.3.8      rlang_1.1.2        Rcpp_1.0.11        xtable_1.8-4      
[71] glue_1.6.2         DBI_1.2.0          renv_1.0.3         pkgload_1.3.3      rstudioapi_0.15.0  jsonlite_1.8.8     R6_2.5.1          
[78] fs_1.6.3           units_0.8-5       

RStudio Server
2023.09.1 Build 494
>