Skip to content

GPU memory leak when removing then inserting a mesh from Assets #18808

@g-pascal

Description

@g-pascal

Bevy version

0.15.3, 0.16.0-dev

[Optional] Relevant system information

`AdapterInfo { name: "NVIDIA GeForce GTX 1070", vendor: 4318, device: 7041, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "572.60", backend: Vulkan }`

What you did

I want to update many meshes in parallel. I start by collecting the meshes with meshes.remove(handle), update the meshes in a par_splat_map_mut, then reinsert the meshes with meshes.insert(handle, mesh).

Simplified code: https://gist.github.com/g-pascal/eeab0d104fe8f2725b36c3bfb2c034e2

What went wrong

The process crashed after a few minutes due to a failed memory allocation. Looking at the Windows task manager it is quite clear there is a leak somewhere:

Additional information

This seems related to #16586 which fixed leaks caused by simply using meshes.get_mut(handle). I'm having the same issue but when inserting an already allocated mesh with an existing handle:

    let mesh = meshes.remove(&*mesh_handle).unwrap();
    // update mesh...
    meshes.insert(mesh_handle, mesh);

The leak also happens when the mesh is not updated at all, simply removing it and reinserting it causes the same issue.

Minimal reproduction: https://gist.github.com/g-pascal/08ad6f56ea4699ecefb25cb65945ee75

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions