-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Despawning causes panics #135
Comments
Yeah this makes sense to me. Im pretty sure the problem here is the array metadata for gpu-mapped components getting out of sync with the entities. I think we arent handling entity removal correctly in that part of the code. I'll look into this. Despawning is important 😄 |
I've encountered this as well. Here's code that reproduces the issue. use bevy::prelude::*;
struct DecayerTimer(Timer);
struct Decayer(f32);
fn decayer_system(
mut commands: Commands,
time: Res<Time>,
mut timer: ResMut<DecayerTimer>,
mut query: Query<(Entity, &mut Decayer)>,
) {
timer.0.tick(time.delta_seconds);
if timer.0.finished {
commands
.spawn_as_entity(
Entity::new(),
SpriteComponents {
sprite: Sprite {
size: Vec2::new(50.0, 50.0),
},
..Default::default()
},
)
.with(Decayer(2.0));
timer.0.reset();
println!("Spawned a decayer");
}
for (entity, mut decayer) in &mut query.iter() {
decayer.0 -= time.delta_seconds;
if decayer.0 <= 0.0 {
commands.despawn(entity);
println!("Deleted decayer: {:?}", entity);
}
}
}
fn init(mut commands: Commands) {
commands.spawn(Camera2dComponents::default());
}
fn main() {
App::build()
.add_default_plugins()
.add_resource(DecayerTimer(Timer::from_seconds(0.25)))
.add_startup_system(init.system())
.add_system(decayer_system.system())
.run();
} |
I'm also getting this error when trying to despawn cubes in a system: It despawns the first one fine, then crashes. In my example I am spawning a cube every second and then despawning them when they move to a specific point. Do I need to free any render resources? I put together a fairly minimal example here as a gist: |
I have this issue too. Whenever I change ui screens, I try to despawn the previous entities, but it causes the |
I'm seeing this issue too. My game spawns objects at the top of the screen and despawns them when they fall to the bottom. These two systems spawn and despawn them: fn asteroid_creator_system(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
time: Res<Time>,
mut timer: ResMut<AsteroidTimer>,
) {
let mut rng = rand::thread_rng();
timer.0.tick(time.delta_seconds);
if timer.0.finished {
println!("spawn asteroid");
commands
.spawn(SpriteComponents {
material: materials.add(Color::rgb(0.2, 0.2, 0.8).into()),
translation: Translation(Vec3::new(rng.gen_range(-400.0, 400.0), 400.0, 0.0)),
sprite: Sprite {
size: Vec2::new(30.0, 30.0),
},
..Default::default()
})
.with(Asteroid)
.with(Gravity);
timer.0.reset();
}
}
fn asteroid_destroyer_system(
mut commands: Commands,
mut query: Query<(&Asteroid, &mut Translation, Entity)>,
) {
for (_asteroid, translation, entity) in &mut query.iter() {
if translation.0.y() < -400.0 {
commands.despawn(entity);
}
}
} |
There is a pr for a fix that worked for me. It hasn't been merged yet, but you can use it by putting this in your cargo.toml |
…nces as get_or_assign_index will now always assign (bevyengine#247)
Trying out bevy and started with a player that can shoot bullets. Ran into an issue where spawning more bullets after despawning one causes a panic. Usually need to spawn 2 bullets after one was despawned.
Running on Pop!_OS (basically Ubuntu) with a Ryzen 3700X + GTX TI 1080 and NVIDIA proprietary drivers (version 418.152.00).
Full stacktrace:
Code:
The text was updated successfully, but these errors were encountered: