Skip to content

MeshAllocator leaks GPU memory on in-place mesh modification #24892

Description

@ivall

Bevy version and features

0.19.0, default features.

Relevant system information

  • Rust: stable (latest)
  • OS: Windows 11
  • AdapterInfo { name: "AMD Radeon RX 9070", vendor: 4098, device: 30032, device_type: DiscreteGpu, backend: Vulkan }

What you did

Repeatedly modified existing Mesh assets in place (destructible voxel bodies re-meshed on every hit). Reduced to: spawn entities each with their own Mesh3d, then each frame mutate every mesh in place, reassigning identical data is enough to trigger it:

fn churn(mut meshes: ResMut<Assets<Mesh>>, q: Query<&Mesh3d>) {
    for h in &q {
        if let Some(mut m) = meshes.get_mut(&h.0) { *m = build_mesh(); }
    }
}

What went wrong

Expected: re-uploading a modified mesh frees/reuses its previous GPU allocation, so steady-state memory is bounded.

Actual: get_mut (raising AssetEvent::Modified) never frees the mesh's previous allocation in MeshAllocator's general slabs, so every modification leaks the old buffer. Process commit/VRAM grows without bound while the CPU-side Assets<Mesh> count and all ECS state stay flat. With ~32 meshes re-uploaded/frame, commit climbs ~27 MB/s indefinitely (1.1 -> 2.2 GB in 42 s).

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 behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesP-HighThis is particularly urgent, and deserves immediate attentionS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    Status
    Done
    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions