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

World.spawn(()) panics with index out of bounds #6226

Closed
alice-i-cecile opened this issue Oct 10, 2022 · 2 comments
Closed

World.spawn(()) panics with index out of bounds #6226

alice-i-cecile opened this issue Oct 10, 2022 · 2 comments
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior
Milestone

Comments

@alice-i-cecile
Copy link
Member

world.spawn(()) seems to panic with "index out of bounds: the len is 0 but the index is 0". But commands.spawn(()) seems fine.

Originally posted by @Zeenobit in #6186 (comment)

This bug was introduced with @cart's #6054. I think it's important that we fix this for 0.9 to avoid introducing nasty crashes in people's code.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events labels Oct 10, 2022
@alice-i-cecile alice-i-cecile added this to the Bevy 0.9 milestone Oct 10, 2022
@BoxyUwU
Copy link
Member

BoxyUwU commented Oct 11, 2022

while carts PR does introduce this, get_bundle_spawner seems to just have been wrong since it was introduced, cmds.spawn_bundle(()) does .spawn().insert(()) internally which uses get_bundle_inserter which isnt buggy

@BoxyUwU
Copy link
Member

BoxyUwU commented Oct 11, 2022

BundleSpawner currently holds a reference to an AddBundle and also &mut to the Archetype so something has to change here in order to make this work. tangentially: BundleInserter has a // PERF fixme about storing an &AddBundle along side the &mut Archetype which is funny considering that is exactly the problem here

bors bot pushed a commit that referenced this issue Nov 3, 2022
# Objective

Alternative to #6424 
Fixes #6226

Fixes spawning empty bundles

## Solution

Add `BundleComponentStatus` trait and implement it for `AddBundle` and a new `SpawnBundleStatus` type (which always returns an Added status). `write_components` is now generic on `BundleComponentStatus` instead of taking `AddBundle` directly. This means BundleSpawner can now avoid needing AddBundle from the Empty archetype, which means BundleSpawner no longer needs a reference to the original archetype.

In theory this cuts down on the work done in `write_components` when spawning, but I'm seeing no change in the spawn benchmarks.
@bors bors bot closed this as completed in 2e653e5 Nov 3, 2022
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Alternative to bevyengine#6424 
Fixes bevyengine#6226

Fixes spawning empty bundles

## Solution

Add `BundleComponentStatus` trait and implement it for `AddBundle` and a new `SpawnBundleStatus` type (which always returns an Added status). `write_components` is now generic on `BundleComponentStatus` instead of taking `AddBundle` directly. This means BundleSpawner can now avoid needing AddBundle from the Empty archetype, which means BundleSpawner no longer needs a reference to the original archetype.

In theory this cuts down on the work done in `write_components` when spawning, but I'm seeing no change in the spawn benchmarks.
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
2 participants