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

Error: Not freed memory blocks... #1167

Open
freli19 opened this issue Dec 5, 2024 · 0 comments
Open

Error: Not freed memory blocks... #1167

freli19 opened this issue Dec 5, 2024 · 0 comments
Labels
question Question, not yet a bug ;)

Comments

@freli19
Copy link

freli19 commented Dec 5, 2024

Describe the issue

Hello,
I am trying to run a simple script that is like a hybrid of examples/basic/physics_positioning and examples/advanced/point_clouds. After running it a number of times, bproc.object.simulate_physics_and_fix_final_poses() takes longer and longer to run, and when finished I get the print out:
Blender quit
Error: Not freed memory blocks: 9, total unfreed memory 49.438984 MB
Cleaning temporary directory
What can be done to delete or free these memory blocks? I have tried to find the solution but I am yet to succeed. And also, is there a common cause for the accumulation of these?
Thank you!

Minimal code example

bproc.init()
# load blender materials from cubes
blendermetallic = bproc.loader.load_blend("U:/Data\Objekt\Blender/metallic_cube.blend", data_blocks='materials')
# Load the chosen object into the scene
active = []
for i in range(args.num_objects):
    active.append(bproc.loader.load_obj("u:\Data\object.obj")[0])

# load a surface
scene = [bproc.loader.load_obj("U:\Data\plane.obj")[0]]
scene_pos = np.array([0, 0, -1500]) # pose in mm
scene[0].set_location(scene_pos)

# load a bin for objects to fall in to
scene.append(bproc.loader.load_obj("U:\Data/bin.obj")[0])
scene[1].set_location(scene_pos + [0, 0, 110]) # pose in mm

# Make all objects actively participate in the simulation
for obj in active:
    obj.enable_rigidbody(active=True)
    obj.add_material(metallic[1])
    obj.set_cp("category_id", 1)

# The scene should only act as an obstacle and is therefore marked passive.
# To let the objects fall into the valleys of the ground, make the collision shape MESH instead of CONVEX_HULL.
for obj in scene:
    obj.enable_rigidbody(active=False, collision_shape="MESH")

# Define a function that samples the pose of a given sphere
def sample_pose(obj: bproc.types.MeshObject):
    obj.set_location(np.random.uniform(scene_pos + [-150, -150, 300], scene_pos + [150, 150, 500]))
    print(obj.get_location())
    obj.set_rotation_euler(bproc.sampler.uniformSO3())
    
# Sample the poses of all objects above the ground without any collisions in-between
bproc.object.sample_poses(
    active,
    sample_pose_func=sample_pose
)

# Run the simulation and fix the poses of the objects at the end
bproc.object.simulate_physics_and_fix_final_poses(min_simulation_time=4, max_simulation_time=60, check_object_interval=1)

bvh_tree = bproc.object.create_bvh_tree_multi_objects(active + scene)

# define the camera resolution for the pc
bproc.camera.set_resolution(1024, 1024)

bproc.camera.set_intrinsics_from_blender_params(clip_start=1200.0, clip_end=1600.0)
position, euler_rotation = [0, 0, 0], [0, 0, 0]
matrix_world = bproc.math.build_transformation_mat(position, euler_rotation)
bproc.camera.add_camera_pose(matrix_world)

# Compute a depth image from the view of the second camera pose
depth = bproc.camera.depth_via_raytracing(bvh_tree, 1)

# Project the depth again to get a point cloud
points = bproc.camera.pointcloud_from_depth(depth, 1)
points = points.reshape(-1, 3)

bproc.renderer.enable_depth_output(activate_antialiasing=False)

# set camera res for rendering
bproc.camera.set_resolution(512, 512)

# render the whole pipeline
data = bproc.renderer.render()
# Write BOP-data
bproc.writer.write_bop(output_dir = "./output/",
                       target_objects = active,
                       depths = data["depth"],
                       colors = data["colors"],
                       color_file_format = "PNG",
                       append_to_existing_output=True,
                       save_world2cam=True,
                       ignore_dist_thres=3000.0,
                       annotation_unit='m'
                       )

Files required to run the code

No response

Expected behavior

I expect the simulation to finish within 20 seconds as it did before. Now i get the following prints:
Capture
Capture2

BlenderProc version

2.8.0

@freli19 freli19 added the question Question, not yet a bug ;) label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question, not yet a bug ;)
Projects
None yet
Development

No branches or pull requests

1 participant