Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

GLFW Error: GLX: Failed to make context current when using with ROS

Open ShrutheeshIR opened this issue 3 years ago • 3 comments
trafficstars

Checklist

Describe the issue

I have been trying to use open3d to visualize point clouds that are sent through a ROS node. As a subscriber node, it reads a point cloud, and just displays on open3d. I get this error 'GLFW Error: GLX: Failed to make context current when using with ROS'.

However, bizarrely, if I do not have the display function in the callback, and if I write a dummy function to just display a random point cloud, and call the function directly, it works. As soon as the display function is called within a subscriber callback component, I get this GLX error, which seems very weird. Here is a rough snippet.

class Visualizer:
  def __init__(self):
    self.vis = o3d.visualization.Visualizer()
    rospy.Subscriber("/callbacktopic", String, self.callback)
    rospy.spin()

  def callback(self, data):
    self.runner()

  def self.runner(self):
    pcd = o3d.geometry.PointCloud()
    pcd.points = np.random.rand(10,3)
    hull, _ = pcd.compute_convex_hull()
    self.vis.add_geometry(hull)

This fails at the last step with the error in the title, but with a small change to the init function

  def __init__(self):
    self.vis = o3d.visualization.Visualizer()
    self.runner()

This works, i.e. it is able to display a point cloud. This seems like a very weird error caused in open3d, and I'm not sure what the issue is.

If I use o3d.visualization.draw_geometries([pcd]) it fails with a similar GLX error but not the same.

I have an NVidia MX330 graphics card. Interestingly, if I switch to intel graphics, the error goes away.

Steps to reproduce the bug

import numpy as np
import open3d

class Visualizer:
  def __init__(self):
    self.vis = o3d.visualization.Visualizer()
    rospy.Subscriber("/callbacktopic", String, self.callback)
    rospy.spin()

  def callback(self, data):
    self.runner()

  def self.runner(self):
    pcd = o3d.geometry.PointCloud()
    pcd.points = np.random.rand(10,3)
    hull, _ = pcd.compute_convex_hull()
    self.vis.add_geometry(hull)

Error message

No response

Expected behavior

No response

Open3D, Python and System information

- Operating system:  Ubuntu 18.04
- Python version: Python 2.7 (Since I need ROS)
- Open3D version: 0.9
- System type: x84
- Is this remote workstation?: no
- How did you install Open3D?: pip
- Compiler version gcc 7.5

Additional information

No response

ShrutheeshIR avatar Jan 27 '22 11:01 ShrutheeshIR

Hi, I've got a very similar issue and I think it has something to do with using an OpenGL Context in a different Thread. Did you find a solution to that problem?

nicolas-schreiber avatar Apr 29 '22 13:04 nicolas-schreiber

+1 I am also seeing this error when trying to publish images from MuJoCo Python API within a callback function. I'm considering moving to C++ API to debug further.

peterdavidfagan avatar Feb 01 '24 13:02 peterdavidfagan

You may need to do open3d update asynchronously, I tried to use callback function to save updated information and use main thread to update the visualizer. Since the listener thread is running when a subscriber is created, not using rospy.spin() but use a manual update loop is feasible.

Ericcsr avatar Jul 25 '24 23:07 Ericcsr