legion
legion copied to clipboard
Unsoundness in ResourceSet
This program results in undefined behavior:
use legion::prelude::*;
fn fetcher() -> legion::resource::PreparedRead<u32> {
let mut resources = Resources::default();
resources.insert(0u32);
<Read<u32>>::fetch(&resources)
}
fn main() {
println!("0x{:x}", *fetcher());
}
@jaynus would have to correct me but I think the Prepared* APIs were intended for use inside of System scheduler implementations? PreparedRead has a Safety section, but the ResourceSet impl just returns it without regard to those.
Your correct, it intentionally erases lifetimes for the system usage. I'll need to add another layer of time indirection into the system implementation to erase in a differnt location so it's not exposed to the user.