-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Handles to Assets leaking #4589
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
Comments
Minimal reproduction on linux: use bevy::core::FixedTimestep;
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
const COUNT: usize = 1024;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_system_set(
SystemSet::new()
.with_run_criteria(FixedTimestep::steps_per_second(60.))
.with_system(update)
)
.run();
}
fn update(
mut meshes: ResMut<Assets<Mesh>>,
mut mesh_handles: Local<Vec<Handle<Mesh>>>,
) {
mesh_handles.drain(..).for_each(drop);
for _ in 0..COUNT {
mesh_handles.push(meshes.add(Mesh::from(shape::Cube::default())));
}
println!("{:?}", meshes.into_inner().iter().count() );
} It has something to do with the fixed timestep. The issue is not present if |
the code above runs at less than 60 fps on my computer, so it's running the system several times per frame, every time being slower, so every time running the system more time per frame, which is why the count of meshes keeps increasing |
this is the case on my system as well. fn update(mut meshes: ResMut<Assets<Mesh>>, mut mesh_handles: Local<Vec<Handle<Mesh>>>) {
mesh_handles.drain(..).for_each(|handle| {
meshes
.remove(handle)
.map(drop)
.expect("Failed to remove asset.")
});
mesh_handles
.extend(iter::repeat_with(|| meshes.add(Mesh::from(shape::Cube::default()))).take(COUNT));
println!("{:?}", meshes.into_inner().iter().count());
} |
#5692 might help by letting the |
Bevy version
Applicable to both 0.6 and 0.7
Operating system & version
MacOs Big Sur
What you did
What you expected to happen
Stable FPS, dropping and re-creating meshes on every iteraton of the
update
systemWhat actually happened
Meshes are not freed
The text was updated successfully, but these errors were encountered: