Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue displaying 3D plots in rgl/lidR on MacOS #423

Open
ColinPSweeney opened this issue Jun 13, 2024 · 9 comments
Open

Issue displaying 3D plots in rgl/lidR on MacOS #423

ColinPSweeney opened this issue Jun 13, 2024 · 9 comments

Comments

@ColinPSweeney
Copy link

I am having an issue displaying LiDAR pointclouds using lidR/rgl since updating my MacOS operating system to macOS Sonoma 14.3.1 and lidR package to version 4.1.1. I am currently using rgl version 1.3.1

Previously I was able to plot pointclouds in a previous version of lidR using XQuartz. When I try lidR::plot(las), I don't get any errors or plots.

lidR uses the rgl package to create it's 3D plots. When I tried library(rgl), I get the following error:
"This build of rgl does not include OpenGL functions. Use rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE)."

I am able to get some 3D plots to work using:

options(rgl.printRglwidget = TRUE)

AND

with(iris, plot3d(Sepal.Length, Sepal.Width, Petal.Length, type="s", col=as.numeric(Species)))

However, this does not fix lidR::plot(las). When I try las plots, not pop up appears.

My guess is that somehow XQuartz is not talking to the rgl package properly. I tried reinstalling XQuartz with homebrew and am currently using version 2.8.5. Not sure if this is an rgl or XQuartz issue, but I thought I would try here first. Any thoughts are appreciated! (Cross posted on stackoverflow here: https://stackoverflow.com/questions/78614609/error-in-displaying-3d-plots-in-rgl-lidr-on-macos)

@dmurdoch
Copy link
Owner

I normally install XQuartz from xquartz.org, and haven't had problems lately. I'm using a newer version of MacOS, Sonoma 14.5.

If you're getting the error message you described on startup, then I think what it says is true: rgl can't find the shared library that links to OpenGL, because it was built without access to it. The CRAN binary version 1.3.1 definitely has both libraries. You can see them by running

list.files(system.file("libs", package="rgl") )
list.files(system.file("useNULL", package="rgl"))

Both directories should contain rgl.so, with the one in libs quite a bit bigger.

It's possible that the message shows up if libs/rgl.so fails to load for some other reason. An incompatible XQuartz is the most likely cause.

@ColinPSweeney
Copy link
Author

Thanks for the input! I tried 2 things this morning. I reinstalled XQuartz from the website (didn't resolve the issue) and then also removed rgl and reinstalled. When I install the binary (1.2.8) I am able to get it to work! When I try installing from source (1.3.1), it cannot connect to OpenGL. It appears there is something about rgl 1.3.1 that my computer doesn't like.

When I tried installing 1.3.1 from source, I there were a couple of warnings:
configure: WARNING: missing required library GL

subscene.cpp:994:7: warning: variable 'index' set but not used [-Wunused-but-set-variable]
int index = 0;
^
1 warning generated.

ld: warning: -single_module is obsolete
ld: warning: -multiply_defined is obsolete

@dmurdoch
Copy link
Owner

Thanks. The warning about index is correct, and can be fixed by deleting the declaration and the line that sets it. I'll do that, but it's harmless, so don't worry about it.

The warning about missing the lib is something that's harder to deal with. I haven't been building rgl on my Mac much lately, but I just tried and it failed. Presumably the configure script isn't finding libGL. I'll see if I can track that down and fix it.

@ColinPSweeney
Copy link
Author

Update. I had to update my R to version 4.4.0 (and R studio 2024.04.2+764). Now that I've gone to this version, 1.3.1 seems to work just fine. Plotting pointclouds on the most recent version of lidR does as well. Looks like it's a combo of 1.3.1 and R version 4.1.1 that might have been the issue (unsure as to the why).

@dmurdoch
Copy link
Owner

I have been looking at building rgl from source on my Mac M3, and have discovered the following. These are more notes to myself, rather than final clear advice at this point:

  • configuration fails to find libX11 unless I add --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib to the configure args
  • If my PATH includes /usr/local/bin ahead of /opt/R/arm64/bin that will cause it to fail. For some reason, RStudio appears to add /usr/local/bin at the head of the PATH, and that triggers issues.
  • If I run R CMD build rgl --no-build-vignettes followed by R CMD INSTALL rgl_1.3.6.tar.gz in a shell where my PATH starts with /opt/R/arm64/bin then things are fine. I only seem to have trouble in RStudio.

@dmurdoch
Copy link
Owner

@ColinPSweeney : If you do a local build with R 4.4.0, are things working now? If not, could you look at the config.log file after a build attempt, and let me know what is shown for the PATH lines at the end of the Platform. section? I am getting successful builds when that contains /opt/R/arm64/bin first.

@ColinPSweeney
Copy link
Author

@dmurdoch Is a local build different from downloading from source? After upgrading to R Studio (2024.04.2+764) and R (4.4.0: using [R-4.4.0-x86_64.pkg] for older macs), I was able to download rgl 1.3.1 from source and got it to work. I neglected to make note of what version of R studio I was using previously but I think my R was version 4.1.1

I tried to look for the fonfig.log file at this filepath: "/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rgl" but didn't see it. Happy to try and look for it in another directory/if there is a different method for doing a local build!

@dmurdoch
Copy link
Owner

I think you'll only get config.log if you download (or use git to check out) the source and then build it. For example, in RStudio you can ask to create a new project from the git repository https://github.com/dmurdoch/rgl; it handles the downloading and setup, then you would click on Install in the Build pane.

I think you probably installed a binary build from CRAN; those are fine. With the older R version there are no binaries available, so you probably would have downloaded the .tar.gz file and built that. I haven't done that in a while, but I think by default it cleans up afterwards and you wouldn't see the config.log.

@ColinPSweeney
Copy link
Author

ColinPSweeney commented Jun 17, 2024

Gotcha! Yeah it appears as if I stumbled upon the right combination of software versions that were not compatible. As you said in your previous comments, it might be down to a filepath issue (which might have been fixed with the updated R Studio). Interesting that rgl 1.2.8 worked from binary though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants