Skip to content

MjSceneParser.create_scene doesn't clean up properly #12

@zchuning

Description

@zchuning

In MjSceneParser.create_scene, the all_objects variable is a itertools.chain object which is exhausted after the first iteration. This means self.cleanup(all_objects) always receives an empty iterator. This results in a new temporary robot xml file being created under d3il_sim/model/mj/robots/ each time an environment is instantiated. Below is a proposed fix.

def create_scene(self, mj_robots, mj_surrounding, object_list: list, dt):
    if object_list is None:
        object_list = []
    if not isinstance(object_list, list):
        object_list = [object_list]

    # Build a single list so we can iterate multiple times
    all_objects = chain([mj_surrounding], object_list, mj_robots)
    all_objects = [obj for obj in all_objects]

    for obj in all_objects:
        self.load_mj_loadable(obj)

    self.set_dt(dt)

    model = mujoco.MjModel.from_xml_string(self.mj_xml_string, self.assets)
    data = mujoco.MjData(model)

    # all_objects is a real list now, not an exhausted iterator
    self.cleanup(all_objects)
    return model, data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions