isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.19k stars 2.27k forks source link

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

Open ShrutheeshIR opened 2 years ago

ShrutheeshIR commented 2 years ago

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

nicolas-schreiber commented 2 years ago

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?

peterdavidfagan commented 7 months ago

+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.

Ericcsr commented 1 month ago

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.