Skip to content

Commit

Permalink
Gracefully handle invalid DISPLAY variableReplace display error asser…
Browse files Browse the repository at this point in the history
…t with warning, fallback and error (#1282)

If DISPLAY environment variable is misconfigured, resulting in an invalid display pointer:
- try opening the default display :0
- if that fails too, bailout with a fatal error message
  • Loading branch information
josephduchesne authored and rhaschke committed Mar 6, 2019
1 parent 8c2febc commit 5f454b8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/rviz/ogre_helpers/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,18 @@ void RenderSystem::setupDummyWindowId()
dummy_window_id_ = 0;
#else
Display *display = XOpenDisplay(0);
assert( display );

if (display == NULL) {

ROS_WARN("$DISPLAY is invalid, falling back on default :0");
display = XOpenDisplay(":0");

if (display == NULL) {
ROS_FATAL("Can't open default or :0 display. Try setting DISPLAY environment variable.");
throw std::runtime_error("Can't open default or :0 display!\n");
}

}

int screen = DefaultScreen( display );

Expand Down

0 comments on commit 5f454b8

Please sign in to comment.