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

BugFix: thread 'main' panicked at 'index out of bounds: #930

Merged
merged 1 commit into from
Nov 27, 2020

Conversation

Git0Shuai
Copy link
Contributor

Invoke archetype.grow() while archetype.capacity() != archetype.len() will resize entities and data with different sizes.

so, the this program.

use bevy::prelude::*;

fn main() {
    let mut world = World::new();
    for _ in 0..100 {
        world.spawn(("abc".to_string(),));
    }
    world.reserve::<(String,)>(100);
    for _ in 0..100 {
        world.spawn(("abc".to_string(),));
    }
}

panicked:

thread 'main' panicked at 'index out of bounds: the len is 172 but the index is 172', crates\bevy_ecs\src\core\archetype.rs:418:9
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673\/library\std\src\panicking.rs:493
   1: core::panicking::panic_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673\/library\core\src\panicking.rs:92
   2: core::panicking::panic_bounds_check
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673\/library\core\src\panicking.rs:69
   3: core::slice::index::{{impl}}::index_mut<bevy_ecs::core::archetype::ComponentFlags>
             at C:\Users\..\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\index.rs:188
   4: core::slice::index::{{impl}}::index_mut<bevy_ecs::core::archetype::ComponentFlags,usize>
             at C:\Users\..\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\index.rs:26
   5: alloc::vec::{{impl}}::index_mut<bevy_ecs::core::archetype::ComponentFlags,usize,alloc::alloc::Global>
             at C:\Users\..\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\vec.rs:2173
   6: bevy_ecs::core::archetype::Archetype::put_dynamic
             at F:\bevy\crates\bevy_ecs\src\core\archetype.rs:418
   7: bevy_ecs::core::world::{{impl}}::spawn::{{closure}}<tuple<alloc::string::String>>
             at F:\bevy\crates\bevy_ecs\src\core\world.rs:99
   8: bevy_ecs::core::bundle::{{impl}}::put<alloc::string::String,closure-1>
             at F:\bevy\crates\bevy_ecs\src\core\bundle.rs:99
   9: bevy_ecs::core::world::World::spawn<tuple<alloc::string::String>>
             at F:\bevy\crates\bevy_ecs\src\core\world.rs:98
  10: game::main
             at .\src\main.rs:10
  11: core::ops::function::FnOnce::call_once<fn(),tuple<>>
             at C:\Users\..\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

this PR fixed this bug.

@cart
Copy link
Member

cart commented Nov 27, 2020

Ooh very nice catch. Thanks!

@cart cart merged commit 7d4cb70 into bevyengine:master Nov 27, 2020
@fopsdev fopsdev mentioned this pull request Jan 24, 2021
@Git0Shuai Git0Shuai deleted the reserve_panic branch March 23, 2021 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants