2

I'm trying to install rgl on a R 4.2.0 installation that I have installed from source, on a Ubuntu 18.04 system. The package seems to be building correctly, however I get a Segmentation fault when R tries to test whether it can load the package. This happens whether I install from CRAN or directly from the rgl repo:

[...]
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Segmentation fault (core dumped)
ERROR: loading failed

any idea of what is going on or what I could check?

EDIT 1

I tried following the suggestion of @user2554330, installed the package skipping the post-install check and then loaded it in an R session under a debugger (I used valgrind). Here's the trace, it's not very helpful to me but hopefully to you:

==36041== Conditional jump or move depends on uninitialised value(s)
==36041==    at 0x56914B7: __wmemchr_avx2 (memchr-avx2.S:275)
==36041==    by 0x55EC518: internal_fnwmatch (fnmatch_loop.c:168)
==36041==    by 0x55EF987: fnmatch@@GLIBC_2.2.5 (fnmatch.c:434)
==36041==    by 0x16F2EB35: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x55E1FA3: __scandir_tail (scandir-tail.c:54)
==36041==    by 0x16F2EE6D: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x16E52A98: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x14940103: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==36041==    by 0x14932F37: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==36041==    by 0x1492E5C3: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==36041==    by 0x1492EFA4: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==36041==    by 0x12C9B5EC: rgl::X11GUIFactory::createWindowImpl(rgl::Window*) (x11gui.cpp:662)
==36041==
==36041== Conditional jump or move depends on uninitialised value(s)
==36041==    at 0x5691497: __wmemchr_avx2 (memchr-avx2.S:264)
==36041==    by 0x55EC518: internal_fnwmatch (fnmatch_loop.c:168)
==36041==    by 0x55EF987: fnmatch@@GLIBC_2.2.5 (fnmatch.c:434)
==36041==    by 0x16F2EB35: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x55E1FA3: __scandir_tail (scandir-tail.c:54)
==36041==    by 0x16F2EE6D: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x16F2ADD1: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x1693F41C: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x169391EA: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x16E52AA0: ??? (in /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)
==36041==    by 0x14940103: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==36041==    by 0x14932F37: ??? (in /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0)
==36041==
==36041== Invalid read of size 8
==36041==    at 0x12C8EC50: rgl::Window::on_close() (gui.cpp:306)
==36041==    by 0x12C79B83: rgl::DeviceManager::createTestWindow() (devicemanager.cpp:171)
==36041==    by 0x12C8EE67: rgl_init (init.cpp:97)
==36041==    by 0x4F38F03: ??? (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F7B2AA: ??? (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F8565F: Rf_eval (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F8746E: ??? (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F88236: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F7C093: ??? (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F8565F: Rf_eval (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F8746E: ??? (in /usr/lib/R/lib/libR.so)
==36041==    by 0x4F88236: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==36041==  Address 0x20 is not stack'd, malloc'd or (recently) free'd

EDIT 2

After this, I tried turning on rgl debug before loading it:

> options(rgl.debug=TRUE)
> library(rgl)
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast

 *** caught segfault ***
address 0x20, cause 'memory not mapped'

Traceback:
 1: rgl.init(initValue, onlyNULL)
 2: fun(libname, pkgname)
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch(fun(libname, pkgname), error = identity)
 7: runHook(".onLoad", env, package.lib, package)
 8: loadNamespace(package, lib.loc)
 9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch({    attr(package, "LibPath") <- which.lib.loc    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return && !quietly)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
13: library(rgl)

seems like it might be connected to the swrast driver.

tmt
  • 83
  • 4
  • 1
    You can install it with the option `INSTALL_opts="--no-test-load"` to avoid the test load on install, then run R under a debugger and try to load it using the usual `library(rgl)`. The debugger should tell you where the segfault is happening. – user2554330 Aug 18 '22 at 15:37
  • @user2554330 does this mean they should run `Sys.setenv(INSTALL_opts="--no-test-load")` then attempt to install the package? – stevec Aug 18 '22 at 15:45
  • 1
    No, run `install.packages("rgl", INSTALL_opts="--no-test-load")`. – user2554330 Aug 18 '22 at 15:47
  • 1
    And "run under a debugger" means running R using `R -d gdb` if `gdb` is your debugger, then at the `gdb` prompt, type `run`. – user2554330 Aug 18 '22 at 15:48
  • @user2554330 hadn't come across either before. Hope it works – stevec Aug 18 '22 at 15:51
  • thanks @user2554330, I followed your suggestion and updated the text of my original post with the output of the debugger – tmt Aug 19 '22 at 07:00

2 Answers2

0

I'm not sure if it will help, but you could try this, namely:

  1. Run sudo nano ~/.profile
  2. Add the line:
export MESA_LOADER_DRIVER_OVERRIDE=i965
  1. Close R and start a new R session, then try the package installation again.
stevec
  • 41,291
  • 27
  • 223
  • 311
  • 1
    Thanks @stevec - I tried this but unfortunately it didn't make any difference – tmt Aug 19 '22 at 06:53
0

It looks to me as though rgl initialization failed, but the error wasn't handled properly, leading to your segfault. The important messages are

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast

which caused the initialization failure. Then the invalid read of size 8 happened when the cleanup code tried to clean something up that had never been created.

rgl should fix the cleanup code so you don't get a segfault. To avoid that issue, you have two choices:

  1. Figure out what went wrong with swrast, and fix it. This question might be relevant: libGL error: failed to load driver: swrast - Running Ubuntu Docker container on Mac OS X host .

  2. Skip trying to use OpenGL within rgl, by setting the R option options(rgl.useNULL = TRUE) before loading rgl. It won't display anything within the R session, but the rglwidget() function will create displays that can be viewed in a browser or in RStudio's viewer.

What rgl should do is automatically fall back to #2 when the initialization fails; after the bug is fixed that should happen.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Thanks again @user2554330 ! Your `options(rgl.useNULL = TRUE)` suggestion indeed works. And thank you as well for the Issue and PR on the `rgl` GitHub! Ideally I would rather fix the driver issue as it can be a problem with other software, however I can't seem to figure out what's wrong with it - I'm running on bare metal (not a container), I have installed and reinstalled the packages I need, all symlinks to the library files for libGL seem ok, I'm not sure what else is worth checking – tmt Aug 19 '22 at 14:15
  • hi, @user2554330 I've tried installing the new `rgl` version (0.109.16) from GitHub using `devtools::install_github()`. The installation completes without errors, however I get exactly the same Segfault with the same trace when I try to load the package. Any idea? Thank you again! – tmt Aug 22 '22 at 07:18