bevyengine / bevyengine/bevy

Handles to Assets leaking

Open
#4,589 4 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Bug C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
4d 8m
Merged PRs (30d)
147

Description

## Bevy version
Applicable to both 0.6 and 0.7

## Operating system & version
MacOs Big Sur

## What you did

```rust
use bevy::core::FixedTimestep;
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::sprite::MaterialMesh2dBundle;

const SCALE: f32 = 32.;
const GRID: usize = 16;

#[derive(Default)]
pub struct Grid([[f32; GRID]; GRID]);

#[derive(Default)]
pub struct GridElems([[Option; GRID]; GRID]);

#[derive(Component)]
pub struct Idx([usize; 2]);

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_startup_system(setup)
.add_system_set(
SystemSet::new()
.with_run_criteria(FixedTimestep::steps_per_second(60.))
.with_system(noisify)
.with_system(update)
)
.init_resource::()
.init_resource::()
.run();
}

fn setup(mut commands: Commands, mut meshes: ResMut>, mut mats: ResMut>) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
}

fn noisify(
mut commands: Commands,
grid: ResMut,
) {
grid.into_inner().0.iter_mut().for_each(|row| {
row.iter_mut().for_each(|e| {
*e = ::rand::random();
})
})
}

fn update(
mut commands: Commands,
grid: Res,
mut elems: ResMut,
mut meshes: ResMut>,
mut mats: ResMut>) {
if !grid.is_added() && !grid.is_changed() {
return;
}
let elems = elems.into_inner();

for x in 0..GRID {
for y in 0..GRID {
if let Some(elem) = elems.0[y][x] {
commands.entity(elem).despawn_recursive();
}
}
}

for y in 0..GRID {
for x in 0..GRID {
elems.0[y][x] = Some(
commands.spawn_bundle(MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(shape::Quad::default())).into(),
material: mats.add(ColorMaterial::from(Color::from([0.0, grid.0[y][x], 0.0]))).into(),
transform: Transform::default().with_scale(Vec3::splat(SCALE))
.with_translation(Vec3::new(SCALE * x as f32, SCALE * y as f32, 0.0)),
..Default::default()
}).id());
}
}

println!("{:?}", meshes.into_inner().iter().count() );
}
// fn greet_people(time: Res

```
## What you expected to happen

Stable FPS, dropping and re-creating meshes on every iteraton of the `update` system

## What actually happened

Meshes are not freed

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.