Skip to content

Commit

Permalink
support assets of any size (bevyengine#1997)
Browse files Browse the repository at this point in the history
Fixes bevyengine#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
  • Loading branch information
mockersf authored and ostwilkens committed Jul 27, 2021
1 parent 82c7e29 commit d4efe2f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
if let HandleId::AssetPathId(id) = handle_id {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'a> LoadContext<'a> {
/// The result of loading an asset of type `T`
#[derive(Debug)]
pub struct AssetResult<T: Component> {
pub asset: T,
pub asset: Box<T>,
pub id: HandleId,
pub version: usize,
}
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<T: AssetDynamic> AssetLifecycle for AssetLifecycleChannel<T> {
self.sender
.send(AssetLifecycleEvent::Create(AssetResult {
id,
asset: *asset,
asset,
version,
}))
.unwrap()
Expand Down

0 comments on commit d4efe2f

Please sign in to comment.