Skip to content

Conversation

@mockersf
Copy link
Member

Objective

Solution

  • Only mark removed assets as modified if they are in the MAIN_WORLD

Testing

  • Run example mesh2d_manual

@mockersf mockersf added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-Assets Load files from disk to use for things like images, models, and sounds labels Apr 13, 2025
@mockersf mockersf added this to the 0.16 milestone Apr 13, 2025
@mockersf mockersf requested a review from tychedelia April 13, 2025 09:40
Copy link
Contributor

@JMS55 JMS55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, but man RenderAsset is getting increasingly cursed D:

@tychedelia
Copy link
Member

Ugh, good catch. Hmm. Let me check to make sure this doesn't regress the memory leak.

@tychedelia
Copy link
Member

tychedelia commented Apr 13, 2025

Ugh so I can still reproduce it with:

use bevy::{
    asset::RenderAssetUsages,
    prelude::*,
    render::mesh::{Indices, PrimitiveTopology},
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, touch)
        .run();
}

fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
    // Spawn a big mesh to make the memory leak obvious
    commands.spawn(Mesh2d(
        meshes.add(
            Mesh::new(
                PrimitiveTopology::TriangleList,
                RenderAssetUsages::RENDER_WORLD,
            )
                .with_inserted_indices(Indices::U32([0; 600_000].to_vec()))
                .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, [[0.0; 3]; 400_000].to_vec()),
        ),
    ));
}

fn touch(q_mesh_handle: Query<&Mesh2d>, mut meshes: ResMut<Assets<Mesh>>) {
    let mesh_handle = q_mesh_handle.single().unwrap();
    // let mesh = meshes.remove(&*mesh_handle).unwrap();
    meshes.insert(mesh_handle,  Mesh::new(
        PrimitiveTopology::TriangleList,
        RenderAssetUsages::RENDER_WORLD,
    )
        .with_inserted_indices(Indices::U32([0; 600_000].to_vec()))
        .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, [[0.0; 3]; 400_000].to_vec()),);
}

Which is like, a stupid pattern but I could see someone doing by accident.

I'd like to try to understand why the custom mesh disappears.

@mockersf
Copy link
Member Author

mockersf commented Apr 14, 2025

I'd like to try to understand why the custom mesh disappears.

The complete fix is probably something that would handle the three asset queues for modified, unused and removed differently and depending on the asset usage, but I would probably be less happy to include that in the 0.16 at this point in the rc process

@mockersf
Copy link
Member Author

closed in favour of #18845

@mockersf mockersf closed this Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants