Skip to content

[Bug]: TypeError with Camera "follow_entity" method #1927

@EZ-Blue

Description

@EZ-Blue

Bug Description

Very small bug:

I'm encountering a [ERROR] TypeError: 'NoneType' object does not support item assignment when trying to use the follow_entity() method of the Camera class.

This happens when the argument fix_orientation is passed with the value True AND no argument is provided for smoothing.

In camera.py in the update_following method it sets camera_lookat = None if fix_orientation == True.

If smoothing is also None, then it enters an else statement that attempts to directly set the camera_pos[:] and camera_lookat[:] to the entity_pos, which raises the NoneType item assignment error since camera_lookat is still None. This is Lines 349-350 in camera.py.

This doesn't happen when a value is provided for the smoothing argument since camera_lookat just isn't updated, so I'm not sure if the fix_orientation method was only intended to be used along with some smoothing value.

I've attached a minimal code to reproduce the error.

Steps to Reproduce

If possible, provide a script triggering the bug, e.g.

# code snippet triggering the bug
import genesis as gs

def main():
    
    gs.init()
    
    device = gs.device

    scene = gs.Scene(
        sim_options=gs.options.SimOptions(dt=0.01, substeps=2),
        viewer_options=gs.options.ViewerOptions(
            camera_pos=(3.5, 0.0, 2.5),
            camera_lookat=(0.0, 0.0, 0.5),
            camera_fov=40,
            max_FPS=60,
        ),
        vis_options=gs.options.VisOptions(
            rendered_envs_idx=list(range(1)),
        ),
        profiling_options=gs.options.ProfilingOptions(show_FPS=False),
        show_viewer=True,
    )

    plane = scene.add_entity(morph=gs.morphs.Plane())

    # Add camera
    cam = scene.add_camera(
            res=(640, 480),
            pos=(3.5, 0.0, 2.5),
            lookat=(0, 0, 0.7),
            fov=40,
            GUI=True,
        )
    
    franka = scene.add_entity(
        gs.morphs.MJCF(
            file="xml/franka_emika_panda/panda.xml",
        ),
    )

    scene.build()

    cam.follow_entity(franka, fix_orientation=True)

    for i in range(1000):
        scene.step()

if __name__ == "__main__":
    main()

Expected Behavior

Camera should update to look at the specified entity without raising error.

Screenshots/Videos

No response

Relevant log output

Environment

  • OS: Ubuntu 22.04
  • GPU: RTX 5080
  • GPU-driver version: 570.195.03
  • CUDA / CUDA-toolkit version: 12.8

Release version or Commit ID

Tested on v0.3.6, v0.3.5 and v0.3.3.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions