support assets of any size (#1997)

Fixes #1892 

The following code is a cut down version of the issue, and crashes the same way:
```rust
enum AssetLifecycleEvent <T> {
    Create(T),
    Free
}

fn main() {
    let (sender, _receiver) = crossbeam_channel::unbounded();
    sender.send(AssetLifecycleEvent::<[u32; 32000]>::Free).unwrap();
}
```

- We're creating a channel that need to be able to hold `AssetLifecycleEvent::Create(T)` which has the size of our type `T`
- The two variants of the enums have a very different size

By keeping `T` boxed while sending through the channel, it doesn't crash
This commit is contained in:
François 2021-04-24 18:14:04 +00:00
parent 38feddb878
commit 0a8576b710
2 changed files with 3 additions and 3 deletions

View File

@ -477,7 +477,7 @@ impl AssetServer {
} }
} }
let _ = assets.set(result.id, result.asset); let _ = assets.set(result.id, *result.asset);
} }
Ok(AssetLifecycleEvent::Free(handle_id)) => { Ok(AssetLifecycleEvent::Free(handle_id)) => {
if let HandleId::AssetPathId(id) = handle_id { if let HandleId::AssetPathId(id) = handle_id {

View File

@ -139,7 +139,7 @@ impl<'a> LoadContext<'a> {
/// The result of loading an asset of type `T` /// The result of loading an asset of type `T`
#[derive(Debug)] #[derive(Debug)]
pub struct AssetResult<T: Component> { pub struct AssetResult<T: Component> {
pub asset: T, pub asset: Box<T>,
pub id: HandleId, pub id: HandleId,
pub version: usize, pub version: usize,
} }
@ -168,7 +168,7 @@ impl<T: AssetDynamic> AssetLifecycle for AssetLifecycleChannel<T> {
self.sender self.sender
.send(AssetLifecycleEvent::Create(AssetResult { .send(AssetLifecycleEvent::Create(AssetResult {
id, id,
asset: *asset, asset,
version, version,
})) }))
.unwrap() .unwrap()