leudz / shipyard

Entity Component System focused on usability and flexibility.
Other
750 stars 45 forks source link

EntityId::dead can not be deserialized #200

Closed SSSxCCC closed 3 months ago

SSSxCCC commented 3 months ago

EntityId::dead can be created in code, and can be serialized, but can not be deserialized:

    let e = shipyard::EntityId::new_from_index_and_gen(0, 0);
    let s = serde_json::to_string(&e).unwrap();
    let e: shipyard::EntityId = serde_json::from_str(&s).unwrap(); // this is ok

    let e = shipyard::EntityId::dead();
    let s = serde_json::to_string(&e).unwrap();
    let e: shipyard::EntityId = serde_json::from_str(&s).unwrap(); // assertion failed: gen <= Self::max_gen()

thread 'main' panicked at C:\Users\SxC.cargo\registry\src\index.crates.io-6f17d22bba15001f\shipyard-0.6.4\src\entity_id\mod.rs:82:9: assertion failed: gen <= Self::max_gen()

    #[inline]
    pub(crate) const fn new_from_parts(index: u64, gen: u16) -> Self {
        assert!(index < Self::INDEX_MASK);
        assert!(gen <= Self::max_gen()); // this assertion failed

        EntityId(unsafe {
            NonZeroU64::new_unchecked((index + 1) | (gen as u64) << Self::INDEX_LEN)
        })
    }
leudz commented 3 months ago

Thanks! (De)serialization is not the best tested part. There is a new version.

SSSxCCC commented 3 months ago

I updated to 0.6.5 and this problem was fixed. Thank you! You are so efficient!

leudz commented 3 months ago

Thank you! Issues are super valuable, even more so currently with 0.7 releasing soon.