Skip to content

Commit 0a8576b

Browse files
committed
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
1 parent 38feddb commit 0a8576b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

crates/bevy_asset/src/asset_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl AssetServer {
477477
}
478478
}
479479

480-
let _ = assets.set(result.id, result.asset);
480+
let _ = assets.set(result.id, *result.asset);
481481
}
482482
Ok(AssetLifecycleEvent::Free(handle_id)) => {
483483
if let HandleId::AssetPathId(id) = handle_id {

crates/bevy_asset/src/loader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a> LoadContext<'a> {
139139
/// The result of loading an asset of type `T`
140140
#[derive(Debug)]
141141
pub struct AssetResult<T: Component> {
142-
pub asset: T,
142+
pub asset: Box<T>,
143143
pub id: HandleId,
144144
pub version: usize,
145145
}
@@ -168,7 +168,7 @@ impl<T: AssetDynamic> AssetLifecycle for AssetLifecycleChannel<T> {
168168
self.sender
169169
.send(AssetLifecycleEvent::Create(AssetResult {
170170
id,
171-
asset: *asset,
171+
asset,
172172
version,
173173
}))
174174
.unwrap()

0 commit comments

Comments
 (0)