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

Spawing many Entities and then despawing them leads to NoSuchEntity. #369

Closed
kakoeimon opened this issue Aug 27, 2020 · 13 comments · Fixed by #393
Closed

Spawing many Entities and then despawing them leads to NoSuchEntity. #369

kakoeimon opened this issue Aug 27, 2020 · 13 comments · Fixed by #393
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior

Comments

@kakoeimon
Copy link

kakoeimon commented Aug 27, 2020

I was trying to create a minimal project for another problem an I came upon this.
The minimal example project is the example ui/text with those lines:

`struct Item {
max_time: f32,
time: f32,
}

fn add_items(mut commands: Commands) {
for _ in 0..1000 {
commands.spawn((Item {max_time: 1.0, time: 0.0}, ));
}

}

fn update_items(mut commands: Commands, time: Res, mut query: Query<(&mut Item, Entity)>) {
let mut num = 0;
for (mut item, e) in &mut query.iter() {
num += 1;
item.time += time.delta_seconds;
if item.time >= item.max_time {
commands.despawn(e);
}
}
println!("number of items : {}", num);
}`

After a while I get:

thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: NoSuchEntity', C:\Users\kakoeimon\.cargo\git\checkouts\bevy-f7ffde730c324c74\89a1d36\crates\bevy_ecs\src\system\commands.rs:75:36 note: run withRUST_BACKTRACE=1environment variable to display a backtrace error: process didn't exit successfully:target\debug\no_such_entity.exe(exit code: 101)

The minimal example project

no_such_entity.zip

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

I confirmed I see the same thing on mac with the current master commit of 3efbaca

Here is an even more stripped down example (I just deleted more things from the example provided above).

no_such_entity.zip

@Ratysz
Copy link
Contributor

Ratysz commented Aug 30, 2020

Most likely related to #117.

@kakoeimon
Copy link
Author

The example project I provided still panics.
I know it is not a real life test but...

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 1, 2020

Are you using the git version of bevy or the crates.io version?
If you're using the crates.io version this fix wont be there until a new a release

@kakoeimon
Copy link
Author

The git, have you tried the example project?

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 1, 2020

Yeah it was what I used to check that the PR fixed the issue it says it does x)
Could you try running cargo clean and then rebuilding and see if that fixes it?

@memoryruins
Copy link
Contributor

Be sure to cargo update the example project too. The sample project's Cargo.lock is behind in changes. Without doing so, I recreate the panic, but after updating, it goes away for me.

@kakoeimon
Copy link
Author

Everything look OK!
cargo clean and cargo update did the trick!
Sorry for my ignorance, I will keep that in mind.
Thanks.

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 1, 2020

Ah oops cargo update, yeah this makes sense. Glad it's working for you now ^-^

@kakoeimon
Copy link
Author

Just to inform you, I got the bug again in my project.
Looks like it was a bad luck, but I thought it will be good to inform you.

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 12, 2020

You'll get the same error message if you despawn the same entity twice (And from some other functions, a stacktrace would be useful if wishing to determine the actual cause :) ). Could be that

@kakoeimon
Copy link
Author

I just found the problem and it was mine.
As you said I despawned the entity twice.
Sorry for bothering you.

@cart
Copy link
Member

cart commented Sep 12, 2020

Not a problem! I'm glad you followed up, even if it ended up being on your side. It could have been an issue with bevy, and we want to fix issues with bevy 😄

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants