-
-
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
Sprites disappearing in 0.1.3 #299
Comments
@Imakoala thanks for adding some info! What's the situation where you get the error? In my case I only get the problem when despawning entities, which causes a panic anyway without 4eb437a anyway, so maybe it would be useful to narrow down the exact situation where the issue arises? |
@hollg I don't despawn anything, but I spawn a lot of components (Tiles for a map), and have a character which moves through that. If you remove commands.despawn(entity) but keep the system do you still have the issue? |
@Imakoala getting rid of the |
I think I've experienced the same issue. I've written an example of the issue: use bevy::prelude::*;
use std::time::Duration;
fn main() {
App::build()
.add_default_plugins()
.add_startup_system(setup.system())
.add_system(fire.system())
.add_system(update.system())
.run();
}
struct Ship {
x: f32,
}
struct Shot {
speed: f32,
}
pub fn setup(mut commands: Commands) {
use bevy::render::camera::{OrthographicProjection, WindowOrigin};
commands
.spawn(Camera2dComponents {
orthographic_projection: OrthographicProjection {
window_origin: WindowOrigin::BottomLeft,
..Default::default()
},
..Default::default()
})
.spawn((
Ship { x: 0. },
Timer::new(Duration::from_millis(120), false), // Shot pace
));
}
fn fire(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
mut query: Query<(&mut Ship, &mut Timer)>,
) {
for (mut ship, mut timer) in &mut query.iter() {
if timer.finished {
timer.reset();
commands
.spawn(SpriteComponents {
material: materials.add(Color::rgb(0.2, 0.8, 0.2).into()),
translation: Translation(Vec3::new(ship.x, 10., 0.0)),
sprite: Sprite {
size: Vec2::new(3.0, 5.0),
},
..Default::default()
})
.with(Shot { speed: 500. });
ship.x += 3.;
}
}
}
fn update(
mut commands: Commands,
time: Res<Time>,
mut query: Query<(Entity, &Shot, &mut Translation)>,
) {
for (entity, shot, mut translation) in &mut query.iter() {
if translation.0.y() > 800. {
commands.despawn(entity);
} else {
*translation.0.y_mut() += time.delta_seconds * shot.speed;
}
}
} The program spawns a lot of bullets moving forward that despawn when they are out of the screen. You'll see that randomly some bullets don't move while their If you think it isn't related, I'll create my own issue. |
I've just ran into similar thing. I'm creating few entities with 2d sprite components - everything seems to work. Then I'm despawning single entity - it disappears from the screen but some other sprite (associated with other entity) also disappears. I isolated this here: https://github.com/mrk-its/bevy-sprite-bug/ After pressing Space key single entity is removed, but two sprites disappear from the screen. |
Looking at this now. Its definitely a priority to fix this. |
I am not sure if it is related, but apart from sprite disappearing, I am also experiencing something like "random sprite shuffling". Reverting 4eb437a prevents the disappearing/shuffling, but then the issue with crash on sprite |
I can confirm: reverting 4eb437a works for me too, moreover, I didn't notice crashes on despawn yet (but I'm testing it on rather small ecs world) |
This should be fixed by #361. Can someone verify that it works for them? |
@cart Just tested and the disappearing is fixed. |
Yep, this fixes the weird behaviour I was getting when despawning entities. |
I upgraded from
0.1.2
to0.1.3
for the fix to despawning entities then spawning new entities causing panics, but now I have a new bug which on the surface feels related. I'm spawningAsteroid
s at the top of the screen and despawning them when they fall to the bottom (the falling is handled by a very simpleGravity
component and a system which updates theTranslation
on anything withGravity
each tick).The first 5
Asteroid
s behave as expected, but after that they disappear after having fallen only a couple of pixels. When I reachAsteroid
number 30, a whole bunch appear on the screen which seem to be part way through their fall.This is the system for despawning:
If I remove this system (and let the
Asteroid
s fall off the screen without despawning them) then the problem disappears.The whole project is very simple and available here: https://github.com/hollg/rusty-robot. I can put together a more minimal reproduction of the bug later if that helps.
The text was updated successfully, but these errors were encountered: