Closed lattice0 closed 2 years ago
On my end, I am seeing the panic happen on the line containing &meshes.get(&x_shape).unwrap()
.
At this point in the code, the mesh has been queued to load but not actually been loaded yet, so the panic on unwrap is expected.
I think I added/rremoved some lines after getting the panic then clicked and got a wrong panic line. How should I wait for the mesh to be loaded then?
Also, to get a handle to a specific mesh in a gltf file, you need to do something like
asset_server.load("quad.gltf#Mesh0/Primitive0")
(see asset_loading.rs which coincidentally loads some meshes)
You can check if an asset's loaded with get_load_state
. Maybe this cheatbook page will be helpful.
Yes I was looking at asset_loading.rs and they don't ever wait for asset loading, also it seems that the asset never loads, as
let x_shape: Handle<Mesh> = asset_server.load("quad.gltf#Mesh0/Primitive0");
while asset_server.get_load_state(&x_shape)!=LoadState::Loaded {
}
let m = &meshes.get(&x_shape);
runs forever.
Maybe #Mesh0/Primitive0
is wrong, it should have another name, but I don't know which one to put, I just made this simple file on Blender and exported
You need to check the load state in separate non-startup system.
But https://github.com/bevyengine/bevy/blob/main/examples/asset/asset_loading.rs does all in one system
asset_loading.rs
never waits for anything to load. It only ever deals with handles to assets that have been queued to load. Bevy's renderer is cool with letting those pop in whenever they end up actually loading.
Your situation is different, because Collider::from_bevy_mesh
needs the actual loaded Mesh
, not a handle.
It might take many frames to load a gltf, so you can't just block on it.
Checkout the cheatbook link above. It's important to store the handle in a Resource or elsewhere so that it's not garbage collected. The example in the cheatbook uses a Vec
of handles and get_group_load_state
, but you can do something similar with a single handle and get_load_state
.
I'm going to close this because I don't think there's a bug here. But please feel free to continue replying, ask another question in the discussions tab, or come and chat in Discord.
Bevy version
0.16.0
[Optional] Relevant system information
Ubuntu 20.04, GPU integrated i7 intel from 2017
What you did
I'm trying to use a mesh as a collision shape using rapier and I get a crash on a very generic line: https://github.com/lattice0/quad/blob/d73a44cbb3d638075a07f5c084a9ccf7e72bd2f0/src/main.rs#L64
please try to run the project from this commit, it should run without any additional efforts
What went wrong
crash
my X shaped drone to be collisionable
a crash
Additional information
backtrace:
Full backtrace: