Flecs-Rust icon indicating copy to clipboard operation
Flecs-Rust copied to clipboard

Sorting causes segfault

Open iiYese opened this issue 1 year ago • 1 comments

Version: db1b212 Minimal setup to reproduce:

use core::cmp::Ordering;
use flecs_ecs::prelude::*;

#[derive(Component)]
struct Foo(u8);

fn foo_cmp(_: Entity, a: &&Foo, _: Entity, b: &&Foo) -> i32 {
    match a.0.cmp(&b.0) {
        Ordering::Less => -1,
        Ordering::Greater => 1,
        Ordering::Equal => 0,
    }
}

fn main() {
    let mut world = World::new();

    world.entity().set(Foo(0));
    world.entity().set(Foo(1));
    
    system!("foo_sort", world, &Foo)
        .kind::<flecs::pipeline::OnStore>()
        .order_by::<&Foo>(foo_cmp)
        .each(|_| {});

    world.progress();
}

iiYese avatar Dec 19 '24 14:12 iiYese

tldr of discord conversation, it's because &T is passed in the order_by function instead of just T, which changes the function signature to &&T which causes the segfault. Need to patch this issue.

Indra-db avatar Dec 19 '24 15:12 Indra-db

fixed in #d2f3b511

Indra-db avatar Nov 03 '25 10:11 Indra-db