amethyst/legion

Panic with `range end index 2 out of range for slice of length 1` with filtering

expenses opened this issue · 0 comments

This is due to the way the filter works I believe. Example code here:

use legion::query::*;
use legion::*;

struct Tag;

struct Position([f32; 3]);

struct Happyness(f32);

#[system]
fn select_tagged(
    tagged: &mut Query<
        (Entity, &Position), EntityFilterTuple<ComponentFilter<Tag>, Passthrough>,
    >,
    world: &legion::world::SubWorld,
) {
    tagged.for_each(world, |(entity, pos)| {
        println!("{:?}: {:?}", entity, pos.0);
    });
}

fn main() {
    let mut schedule = legion::Schedule::builder()
        .add_system(select_tagged_system())
        .build();

    let mut resources = legion::Resources::default();

    let mut world = legion::World::default();

    world.push((Happyness(1.0), Tag));

    world.push((Position([1.0; 3]), Tag));

    schedule.execute(&mut world, &mut resources);
}

if if you remove either of the world.pushes it works fine.

Stack trace:

thread '<unnamed>' panicked at 'range end index 2 out of range for slice of length 1', /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/storage/packed.rs:566:21
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/panicking.rs:92:14
   2: core::slice::index::slice_end_index_len_fail
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/slice/index.rs:41:5
   3: <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/slice/index.rs:238:13
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/slice/index.rs:15:9
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/alloc/src/vec/mod.rs:2381:9
   6: <legion::internals::storage::packed::PackedStorage<T> as legion::internals::storage::ComponentStorage<T>>::iter
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/storage/packed.rs:566:21
   7: <legion::internals::query::view::read::Read<T> as legion::internals::query::view::View>::fetch
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/query/view/read.rs:102:25
   8: <(G,H) as legion::internals::query::view::View>::fetch
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/query/view/mod.rs:212:32
   9: legion::internals::query::Query<V,F>::iter_chunks_unchecked
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/query/mod.rs:386:13
  10: legion::internals::query::Query<V,F>::for_each_unchecked
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/query/mod.rs:683:22
  11: legion::internals::query::Query<V,F>::for_each
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/query/mod.rs:745:18
  12: legion_test::select_tagged
             at ./src/main.rs:17:5
  13: legion_test::select_tagged_system::{{closure}}
             at ./src/main.rs:10:1
  14: <F as legion::internals::systems::system::SystemFn<R,Q>>::run
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/systems/system.rs:222:9
  15: <legion::internals::systems::system::System<R,Q,F> as legion::internals::systems::schedule::Runnable>::run_unsafe
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/systems/system.rs:193:9
  16: legion::internals::systems::schedule::Executor::run_systems
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/systems/schedule.rs:322:21
  17: legion::internals::systems::schedule::Schedule::execute::{{closure}}::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/legion-0.4.0/src/internals/systems/schedule.rs:554:28
  18: rayon_core::join::join::call::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:102:18
  19: rayon_core::join::join_context::call_a::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:124:17
  20: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:344:9
  21: std::panicking::try::do_call
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:379:40
  22: __rust_try
  23: std::panicking::try
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:343:19
  24: std::panic::catch_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:431:14
  25: rayon_core::unwind::halt_unwinding
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5
  26: rayon_core::join::join_context::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/join/mod.rs:141:24
  27: rayon_core::registry::Registry::in_worker_cold::{{closure}}::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:465:21
  28: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::call::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:113:21
  29: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:344:9
  30: std::panicking::try::do_call
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:379:40
  31: __rust_try
  32: std::panicking::try
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:343:19
  33: std::panic::catch_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:431:14
  34: rayon_core::unwind::halt_unwinding
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/unwind.rs:17:5
  35: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:119:38
  36: rayon_core::job::JobRef::execute
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/job.rs:59:9
  37: rayon_core::registry::WorkerThread::execute
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:749:9
  38: rayon_core::registry::WorkerThread::wait_until_cold
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:726:17
  39: rayon_core::registry::WorkerThread::wait_until
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:700:13
  40: rayon_core::registry::main_loop
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:833:5
  41: rayon_core::registry::ThreadBuilder::run
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:55:18
  42: <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::{{closure}}
             at /home/ashley/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.1/src/registry.rs:100:20
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.