haosulab / SAPIEN

SAPIEN Embodied AI Platform
https://sapien.ucsd.edu/
MIT License
427 stars 41 forks source link

KF: Fail to load object: Failed to submit geometry because geometries buffer size has been exceeded. #104

Closed wangyian-me closed 1 year ago

wangyian-me commented 1 year ago

System:

Describe the bug When I try to load an articulation object from partmobility, it reports KF: Fail to load object: Failed to submit geometry because geometries buffer size has been exceeded.

To Reproduce Steps to reproduce the behavior (use pastebin for code):

  1. install sapien2.1.0 and vulkan sdk 1.3.211.0 and nvidia driver 470 or higher
  2. download an objects' urdf
  3. run the script below with xvfb-run -a python ...
import os
from env import Env

flog = open(os.path.join("../data", 'log.txt'), 'w')
env = Env(flog=flog, show_gui=False)
object_material = env.get_material(4, 4, 0.01)
state = 'closed'

for ww in range(5):
    object_urdf_fn = f'../data/where2act_original_sapien_dataset/47669/mobility_vhacd.urdf'
    env.load_object(object_urdf_fn, object_material, state=state)
    env.scene.remove_articulation(env.object)
    print("done ww")

flog.close()
env.close()

Expected behavior

[2023-01-17 19:21:33.529] [kuafu] [info] Camera is not yet usable due to uninitialized context!
[2023-01-17 19:21:33.530] [kuafu] [info] Offscreen mode enabled.
[2023-01-17 19:21:33.530] [kuafu] [warning] Denoiser ON! You must have an NVIDIA GPU with driver version > 470 installed.
done ww
done ww
[2023-01-17 19:21:35.579] [SAPIEN] [error] KF: Fail to load object: Failed to submit geometry because geometries buffer size has been exceeded.
[2023-01-17 19:21:35.581] [SAPIEN] [error] KF: Fail to load object: Failed to submit geometry because geometries buffer size has been exceeded.
[2023-01-17 19:21:35.583] [SAPIEN] [error] KF: Fail to load object: Failed to submit geometry because geometries buffer size has been exceeded.
[2023-01-17 19:21:35.585] [SAPIEN] [error] KF: Fail to load object: Failed to submit geometry because geometries buffer size has been exceeded.
Traceback (most recent call last):
  File "clean_code.py", line 17, in <module>
    env.load_object(object_urdf_fn, object_material, state=state)
  File "/home/vipuser/hierarchyafford/code/env.py", line 86, in load_object
    self.object = loader.load(urdf, {"material": material})
RuntimeError: Failed to submit geometry because geometries buffer size has been exceeded.

Additional context the detailed code of env.py is:

import sapien.core as sapien
from sapien.core import Pose, SceneConfig

import numpy as np

def process_angle_limit(x):
    if np.isneginf(x):
        x = -10
    if np.isinf(x):
        x = 10
    return x

class Env(object):

    def __init__(self, flog=None, show_gui=True, render_rate=20, timestep=1/500, \
            object_position_offset=0.0, succ_ratio=0.1):
        self.current_step = 0

        self.flog = flog
        self.show_gui = show_gui
        self.render_rate = render_rate
        self.timestep = timestep
        self.succ_ratio = succ_ratio
        self.object_position_offset = object_position_offset

        # engine and renderer
        self.engine = sapien.Engine(0, 0.001, 0.005)
        renderer_config = sapien.KuafuConfig()
        renderer_config.use_viewer = False
        renderer_config.spp = 64
        renderer_config.max_bounces = 8
        renderer_config.use_denoiser = True

        self.renderer = sapien.KuafuRenderer(renderer_config)

        self.engine.set_renderer(self.renderer)

        scene_config = SceneConfig()
        scene_config.gravity = [0, 0, -9.81]
        scene_config.solver_iterations = 20
        scene_config.enable_pcm = False
        scene_config.sleep_threshold = 0.0

        self.scene = self.engine.create_scene(config=scene_config)

        self.scene.set_timestep(timestep)

        # add lights
        self.scene.set_ambient_light([0.5, 0.5, 0.5])
        self.scene.add_directional_light([0, 1, -1], [0.5, 0.5, 0.5], shadow=True)
        self.scene.add_point_light([1+object_position_offset, 2, 2], [1, 1, 1], shadow=True)
        self.scene.add_point_light([1+object_position_offset, -2, 2], [1, 1, 1], shadow=True)
        self.scene.add_point_light([-1+object_position_offset, 0, 1], [1, 1, 1], shadow=True)

        # default Nones
        self.object = None
        self.object_target_joint = None

    def load_object(self, urdf, material, state='closed', target_part_id=-1):
        loader = self.scene.create_urdf_loader()

        self.object = loader.load(urdf, {"material": material})
        #self.object = loader.load(urdf, material)
        pose = Pose([self.object_position_offset, 0, 0], [1, 0, 0, 0])
        self.object.set_root_pose(pose)

        # compute link actor information
        self.all_link_ids = [l.get_id() for l in self.object.get_links()]
        self.movable_link_ids = []
        for j in self.object.get_joints():
            if j.get_dof() == 1:
                self.movable_link_ids.append(j.get_child_link().get_id())
        if self.flog is not None:
            self.flog.write('All Actor Link IDs: %s\n' % str(self.all_link_ids))
            self.flog.write('All Movable Actor Link IDs: %s\n' % str(self.movable_link_ids))

        # set joint property
        for joint in self.object.get_joints():
            joint.set_drive_property(stiffness=0, damping=10)

        # set initial qpos
        joint_angles = []
        self.joint_angles_lower = []
        self.joint_angles_upper = []
        target_part_joint_idx = -1
        for j in self.object.get_joints():
            if j.get_dof() == 1:
                if j.get_child_link().get_id() == target_part_id:
                    target_part_joint_idx = len(joint_angles)
                l = process_angle_limit(j.get_limits()[0, 0])
                self.joint_angles_lower.append(float(l))
                r = process_angle_limit(j.get_limits()[0, 1])
                self.joint_angles_upper.append(float(r))
                if state == 'closed':
                    joint_angles.append(float(l))
                elif state == 'open':
                    joint_angles.append(float(r))
                else:
                    raise ValueError('ERROR: object init state %s unknown!' % state)

        self.object.set_qpos(joint_angles)
        if target_part_id >= 0:
            return joint_angles, target_part_joint_idx
        return joint_angles

    def get_material(self, static_friction, dynamic_friction, restitution):
        return self.engine.create_physical_material(static_friction, dynamic_friction, restitution)

We can see that it will not cause any error when I load the object for the first time. But when I load it for the third time, it reports that buffer size has been exceeded. I guess there might be something wrong with env.scene.remove_articulation(), when working with KuafuRenderer. I've tried similar setting in VulkanRenderer and it works well.

fbxiang commented 1 year ago

We have upgraded VulkanRenderer (now renamed SapienRenderer) to include almost all functionalities of KuafuRenderer. Currently it is a beta version but you can install via pip install sapien==2.2b3. We should be able to release a stable version in the next few days. To use the new renderer, first create the VulkanRenderer

    import sapien.core as sapien
    engine = sapien.Engine()
    renderer = sapien.SapienRenderer()  # sapien.VulkanRenderer() still works
    engine.set_renderer(renderer)

Next, add these lines to replace the original KuafuConfig. The key is to use the "rt" shader. These lines can be modified at any time to configure the next created camera. Each camera may use different settings (you can make 1 camera ray tracing and 1 rasterization)

    sapien.render_config.camera_shader_dir = "rt"
    sapien.render_config.viewer_shader_dir = "rt"
    sapien.render_config.rt_samples_per_pixel = 32
    sapien.render_config.rt_max_path_depth = 8
    sapien.render_config.rt_use_denoiser = True  # if NVIDIA driver > 522, some older driver may get lucky but it is not guaranteed
    # other Kuafu parameters are no longer needed

Please let us know if there are still issues with this new renderer.

fbxiang commented 1 year ago

The stable version 2.2.0 has been released and the documentation is updated. Please reopen the issue if the problem persists.