Indra-db / Flecs-Rust

Rust API for Flecs: A Fast and Flexible Entity Component System (ECS)
MIT License
193 stars 11 forks source link

`EntityView::name` returns a reference that can become dangling #172

Closed SkiFire13 closed 3 months ago

SkiFire13 commented 3 months ago
use flecs_ecs::prelude::*;

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

    let e = world.entity_named("foo");
    let name = e.name();
    e.remove_name();

    dbg!(name); // You can still use name

    _ = vec![vec![b'x'; 3]; 100];
    dbg!(name); // This will likely print xxx instead of foo
}

For me this prints:

foo
xxx

Showing that the reference returned by e.name() became dangling.

(Might not be reproducible depending on platform and allocator)

Indra-db commented 3 months ago

returning a cloned String now. Not ideal, but for the time being, it's what needs to be done. Thanks!