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

crash when using egl headless render #302

Open
vipcxj opened this issue Feb 12, 2025 · 0 comments
Open

crash when using egl headless render #302

vipcxj opened this issue Feb 12, 2025 · 0 comments

Comments

@vipcxj
Copy link

vipcxj commented Feb 12, 2025

here is code

main.py

import os
os.environ['PYOPENGL_PLATFORM'] = 'egl'
import open3d as o3d
import renderer as renderer

if __name__ == '__main__':    
    try:
        mesh_src = o3d.io.read_triangle_mesh("XXX.obj")
        renderer.render_to_image(mesh_src, "XXX.jpg")
    except Exception as e:
        print(e)

renderer.py

import open3d as o3d
import trimesh
import numpy as np
import matplotlib.pyplot as plt
import pyrender

def render_to_image(mesh, output_path: str, width=640, height=480):
    _mesh = trimesh.Trimesh(
        vertices=np.asarray(mesh.vertices), 
        faces=np.asarray(mesh.triangles), 
        vertex_normals=np.asarray(mesh.vertex_normals),
        # vertex_colors=np.asarray(mesh.vertex_colors),
    )
    
    scene = pyrender.Scene()
    mesh = pyrender.Mesh.from_trimesh(_mesh)
    scene.add(mesh)
    camera = pyrender.PerspectiveCamera(yfov=np.pi / 3.0)
    camera_pose = np.array([
        [1.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 0.0, -0.5],
        [0.0, 0.0, 1.0, 1.0],
        [0.0, 0.0, 0.0, 1.0]
    ])
    scene.add(camera, pose=camera_pose)
    light = pyrender.PointLight(color=np.ones(3), intensity=10.0)
    scene.add(light, pose=camera_pose)
    
    r = pyrender.OffscreenRenderer(viewport_width=width, viewport_height=height, point_size=1.0)
    
    // crash here, no conole output, no exception, just crash.
    color, depth = r.render(scene)
    
    r.delete()
    
    if output_path is not None and output_path != "":
        plt.imsave(output_path, color)
    
    return color, depth

After debug, I found crash here:

        total_sz = sum(attr_sizes)
        offset = 0
        for i, sz in enumerate(attr_sizes):
            // crash here
            glVertexAttribPointer(
                i, sz, GL_FLOAT, GL_FALSE, FLOAT_SZ * total_sz,
                ctypes.c_void_p(FLOAT_SZ * offset)
            )
            glEnableVertexAttribArray(i)
            offset += sz
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

1 participant