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

Fix segfault on failed rgl.init(). #447

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rgl
Version: 1.3.15
Version: 1.3.16
Title: 3D Visualization Using OpenGL
Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# rgl 1.3.15
# rgl 1.3.16

## Bug fixes

* `triangulate()` now uses the `earcut` library
from https://github.com/mapbox/earcut.hpp, which
should be faster and more reliable than the
previous R implementation.
* In cases where the X11 server did not provide sufficient
support, `rgl.init()` could sometimes segfault. That has
been fixed, and warning messages have been made more
informative.

# rgl 1.3.14

Expand Down
6 changes: 3 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@
ret <- rgl.init(initValue, onlyNULL)

if (!ret) {
warning("'rgl.init' failed, running with 'rgl.useNULL = TRUE'.", call. = FALSE)
options(rgl.useNULL = TRUE)
warning("'rgl.init' failed, will use the null device.\nSee '?rgl.useNULL' for ways to avoid this warning.", call. = FALSE)
onlyNULL <- TRUE
rgl.init(initValue, TRUE)
}

if (!rgl.useNULL())
if (!rgl.useNULL() && !onlyNULL)
setGraphicsDelay(unixos = unixos)

# Are we running in reprex::reprex? If so, do
Expand Down
24 changes: 17 additions & 7 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void Device::notifyDisposed(Disposable* disposable)
// ---------------------------------------------------------------------------
void Device::setName(const char* string)
{
window->setTitle(string);
if (window)
window->setTitle(string);
}
// ---------------------------------------------------------------------------
void Device::update()
Expand All @@ -62,23 +63,27 @@ bool Device::open(void)
// ---------------------------------------------------------------------------
void Device::close(void)
{
if (window)
window->on_close();
}
// ---------------------------------------------------------------------------

void Device::bringToTop(int stay)
{
window->bringToTop(stay);
if (window)
window->bringToTop(stay);
}

void Device::setWindowRect(int left, int top, int right, int bottom)
{
window->setWindowRect(left, top, right, bottom);
if (window)
window->setWindowRect(left, top, right, bottom);
}

void Device::getWindowRect(int *left, int *top, int *right, int *bottom)
{
window->getWindowRect(left, top, right, bottom);
if (window)
window->getWindowRect(left, top, right, bottom);
}

// ---------------------------------------------------------------------------
Expand All @@ -94,12 +99,16 @@ void Device::setIgnoreExtent(int in_ignoreExtent)
// ---------------------------------------------------------------------------
int Device::getSkipRedraw(void)
{
return window->getSkipRedraw();
if (window)
return window->getSkipRedraw();
else
return 0;
}
// ---------------------------------------------------------------------------
void Device::setSkipRedraw(int in_skipRedraw)
{
window->setSkipRedraw(in_skipRedraw);
if (window)
window->setSkipRedraw(in_skipRedraw);
}
// ---------------------------------------------------------------------------
bool Device::clear(TypeID stackTypeID)
Expand Down Expand Up @@ -155,7 +164,8 @@ bool Device::postscript(int format, const char* filename, bool drawText)
void Device::getFonts(FontArray& outfonts, int nfonts, char** family, int* style, double* cex,
bool useFreeType)
{
window->getFonts(outfonts, nfonts, family, style, cex, useFreeType);
if (window)
window->getFonts(outfonts, nfonts, family, style, cex, useFreeType);
}
// ---------------------------------------------------------------------------
const char * Device::getDevtype()
Expand Down
32 changes: 31 additions & 1 deletion src/x11gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,37 @@ WindowImpl* X11GUIFactory::createWindowImpl(Window* window)

flushX();

if (error_code) impl = NULL;
if (error_code) {
switch (error_code) {
case RGL_ERROR_CODE + 1:
Rf_warning("no conforming visual");
break;
case RGL_ERROR_CODE + 2:
Rf_warning("no root window");
break;
case RGL_ERROR_CODE + 3:
Rf_warning("XCreateColormap failed");
break;
case RGL_ERROR_CODE + 4:
Rf_warning("XCreateWindow failed");
break;
case RGL_ERROR_CODE + 5:
Rf_warning("XAllocClassHint failed");
break;
case RGL_ERROR_CODE + 6:
Rf_warning("X11WindowImpl failed");
break;
default:
if (error_code > RGL_ERROR_CODE)
Rf_warning("rgl error %d", error_code - RGL_ERROR_CODE);
else {
char error_text[1024];
XGetErrorText(xdisplay, error_code, error_text, sizeof(error_text));
Rf_warning("X11 error: %s",error_text);
}
}
impl = NULL;
}

// register instance
if (xwindow)
Expand Down
Loading