Skip to content

[Bug]: Segmentation fault when using headless render on Python 3.12 #2977

Description

@Pap-let

Bug Description

I was trying headless rendering on a linux machine, when i use python 3.12 the program throw a Segmentation fault and exit, however python 3.10 works fine.

I'm not sure if this bug can be reproduced since the environment on the team server is not pretty clean.

Steps to Reproduce

Install Python3.12 and Genesis

python3.12 -m venv ./py312-genesis112
./py312-genesis112/bin/python -m pip install genesis-world==1.1.2 
./py312-genesis112/bin/python -m pip install torch --index-url https://download.pytorch.org/whl/cpu

Then run the test script

import os
from pathlib import Path

import genesis as gs
import numpy as np
from PIL import Image


print("PYOPENGL_PLATFORM=", os.environ.get("PYOPENGL_PLATFORM"))
print("DISPLAY=", os.environ.get("DISPLAY"))
print("genesis version=", getattr(gs, "__version__", "unknown"))

gs.init(backend=gs.cpu, precision="32", logging_level="info")

scene = gs.Scene(
    show_viewer=False,
    viewer_options=gs.options.ViewerOptions(
        camera_pos=(1.5, -1.5, 1.0),
        camera_lookat=(0.0, 0.0, 0.2),
        camera_fov=45,
    ),
    vis_options=gs.options.VisOptions(
        shadow=False,
        plane_reflection=False,
        ambient_light=(0.3, 0.3, 0.3),
    ),
)

scene.add_entity(gs.morphs.Plane())
scene.add_entity(
    gs.morphs.Box(
        size=(0.4, 0.4, 0.4),
        pos=(0.0, 0.0, 0.2),
    )
)

cam = scene.add_camera(
    res=(256, 256),
    pos=(1.5, -1.5, 1.0),
    lookat=(0.0, 0.0, 0.2),
    fov=45,
)

scene.build()
rgb, depth, seg, normal = cam.render(rgb=True, depth=True, segmentation=True, normal=True)

arr = np.asarray(rgb)
out = Path("./genesis112_headless_rgb.png")
Image.fromarray(arr).save(out)
print("saved", out)
print("rgb", arr.shape, arr.dtype, int(arr.min()), int(arr.max()), float(arr.mean()))

Can also try python 310 with

python3.10 -m venv ./py310-genesis112
./py310-genesis112/bin/python -m pip install genesis-world==1.1.2 
./py310-genesis112/bin/python -m pip install torch --index-url https://download.pytorch.org/whl/cpu

Expected Behavior

When using python 312 the script throw a segfault when calling cam.render, but python 310 works fine.

Screenshots/Videos

No response

Relevant log output

Current thread 0x00007fa0bf077740 (most recent call first):
  File "xxx/tmp-genesis/lib/python3.12/site-packages/OpenGL/platform/baseplatform.py", line 487 in __call__
  File "xxx/tmp-genesis/lib/python3.12/site-packages/OpenGL/GL/VERSION/GL_2_0.py", line 516 in glVertexAttribPointer
  File "xxx/tmp-genesis/lib/python3.12/site-packages/OpenGL/latebind.py", line 63 in __call__
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/ext/pyrender/primitive.py", line 374 in _add_to_context
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/ext/pyrender/renderer.py", line 688 in _update_context
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/ext/pyrender/renderer.py", line 145 in render
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/ext/pyrender/offscreen.py", line 177 in render
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/vis/rasterizer.py", line 86 in render_camera
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/vis/camera.py", line 454 in render
  File "xxx/tmp-genesis/lib/python3.12/site-packages/genesis/utils/misc.py", line 142 in wrapper
  File "xxx/genesis112_headless_test.py", line 45 in <module>

Environment

  • OS: Ubuntu 22.04
  • GPU/CPU A100/Intel(R) Xeon(R) Platinum 8352Y
  • GPU-driver version 580.159.03
  • CUDA / CUDA-toolkit version 13.0

Release version or Commit ID

Genesis 1.1.2

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions