Skip to content
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

Closed
hollg opened this issue Aug 23, 2020 · 13 comments · Fixed by #361
Closed

Sprites disappearing in 0.1.3 #299

hollg opened this issue Aug 23, 2020 · 13 comments · Fixed by #361
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior P-High This is particularly urgent, and deserves immediate attention

Comments

@hollg
Copy link

hollg commented Aug 23, 2020

I upgraded from 0.1.2 to 0.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 spawning Asteroids at the top of the screen and despawning them when they fall to the bottom (the falling is handled by a very simple Gravity component and a system which updates the Translation on anything with Gravity each tick).

The first 5 Asteroids behave as expected, but after that they disappear after having fallen only a couple of pixels. When I reach Asteroid number 30, a whole bunch appear on the screen which seem to be part way through their fall.

This is the system for despawning:

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);
        }
    }
}

If I remove this system (and let the Asteroids 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.

@Lamakaio
Copy link

Lamakaio commented Aug 23, 2020

I reverted the commits until the issue disappears, and the issue is fixed for me when I reset to 2dadc86. So the problem is probably from the fix to #134 and #135.

Edit : the issue is also fixed when I revert only 4eb437a, which is the fix to #134 and #135.

@karroffel karroffel added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events labels Aug 23, 2020
@hollg
Copy link
Author

hollg commented Aug 23, 2020

@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?

@Lamakaio
Copy link

Lamakaio commented Aug 23, 2020

@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.
The character's sprites stop displaying sometimes, the others don't.
I might post the code later to help with debugging.

If you remove commands.despawn(entity) but keep the system do you still have the issue?
And can you try to revert the commit I pointed out / use https://github.com/Imakoala/bevy (my fork where I just did that) to see if you still have the issue if that's the case ?
Just to be sure we actually have the same issue.

@hollg
Copy link
Author

hollg commented Aug 24, 2020

@Imakoala getting rid of the despawn command gets rid of this issue for me, both when I'm using your fork and when I'm using 0.1.3. I'm not sure what that tells us!

@real-felix
Copy link
Contributor

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 translation value is being modified.

If you think it isn't related, I'll create my own issue.

@mrk-its
Copy link
Member

mrk-its commented Aug 25, 2020

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.

@cart cart added the P-High This is particularly urgent, and deserves immediate attention label Aug 26, 2020
@cart
Copy link
Member

cart commented Aug 26, 2020

Looking at this now. Its definitely a priority to fix this.

@BorisBoutillier
Copy link
Contributor

@cart I think you should start by reverting my PR that tried to fix #135 as this is probably the cause for apparence of this issue. And properly look at #135 ?
I think I am not fluent enough in wgu/bevy to tackle it myself.

@BottledByte
Copy link

I am not sure if it is related, but apart from sprite disappearing, I am also experiencing something like "random sprite shuffling".
I have several textures loaded and despawning some of the instanced sprites occasionally causes wrong texture assignment. For example, asteroids suddenly have a missile texture instead of the asteroid one. To see this happening in practice, you can simply play Per Spatium for a while. Sprites will start disappearing/shuffling.

Reverting 4eb437a prevents the disappearing/shuffling, but then the issue with crash on sprite despawn happens again.

@mrk-its
Copy link
Member

mrk-its commented Aug 26, 2020

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)

@cart cart mentioned this issue Aug 27, 2020
@cart
Copy link
Member

cart commented Aug 27, 2020

This should be fixed by #361. Can someone verify that it works for them?

@kakoeimon
Copy link

@cart Just tested and the disappearing is fixed.
Cannot comment on despawn.

@hollg
Copy link
Author

hollg commented Aug 27, 2020

Yep, this fixes the weird behaviour I was getting when despawning entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior P-High This is particularly urgent, and deserves immediate attention
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants