-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bevy panics with certain skinned meshes #9021
Comments
blender is crashing for me when trying to export this model as a gltf. Could you try to reduce the model as much as possible and still reproduce the issue? |
I just got this panic, but it only happened once! I was unable to trigger it again running the same build.
|
Managed to reproduce it by accident! Was trying to create a new instance of a mesh from a gltf scene that had been spawned via SceneBundle. I was cloning the mesh handle and spawning a new PbrBundle with it and it panics every time. Minimal reproduction here: Update: |
Aggressive Googling led to me this issue! I'm hitting the exact same error when rendering a SceneBundle from a .gltf with animation and bone data. I've also got a minimal reproducible here which includes the .gltf assets. In my case, I generated the .gltf from an Unreal Engine Skeletal Mesh with a dancing animation applied. It seems to be a valid .gltf by all accounts: I'm able to load it in a variety of (non-Bevy) viewers without problems (the mesh is skinned and the animation works). I noticed that if I spawned a PbrBundle from the mesh and material in the scene, Bevy would render it just fine. So, something being wrong with the skeletal data seemed to make sense to me. (But I can't make heads or tails of the wgpu code that raises this error.) |
Thank you all for the small reproducible models. I've some clue as to what is going on, but I needed some lighter models to test it on. I'm going to spend some times today on this |
I have a fix in #9338, could you test if it works on all your cases? |
Woohoo! I tested your branch on my mini repro and it did the trick! Great work! |
# Objective - Fixes part of #9021 ## Solution - Joint mesh are in format `Unorm8x4` in some gltf file, but Bevy expects a `Float32x4`. Converts them. Also converts `Unorm16x4` - According to gltf spec: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#skinned-mesh-attributes > WEIGHTS_n: float, or normalized unsigned byte, or normalized unsigned short
# Objective - Meshes with a higher number of joints than `MAX_JOINTS` are crashing - Fixes partly #9021 (doesn't crash anymore, but the mesh is not correctly displayed) ## Solution - Only take up to `MAX_JOINTS` joints when extending the buffer
…engine#9338) # Objective - Fixes part of bevyengine#9021 ## Solution - Joint mesh are in format `Unorm8x4` in some gltf file, but Bevy expects a `Float32x4`. Converts them. Also converts `Unorm16x4` - According to gltf spec: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#skinned-mesh-attributes > WEIGHTS_n: float, or normalized unsigned byte, or normalized unsigned short
# Objective - Meshes with a higher number of joints than `MAX_JOINTS` are crashing - Fixes partly bevyengine#9021 (doesn't crash anymore, but the mesh is not correctly displayed) ## Solution - Only take up to `MAX_JOINTS` joints when extending the buffer
…engine#9338) # Objective - Fixes part of bevyengine#9021 ## Solution - Joint mesh are in format `Unorm8x4` in some gltf file, but Bevy expects a `Float32x4`. Converts them. Also converts `Unorm16x4` - According to gltf spec: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#skinned-mesh-attributes > WEIGHTS_n: float, or normalized unsigned byte, or normalized unsigned short (cherry picked from commit 3aad5c6)
# Objective - Meshes with a higher number of joints than `MAX_JOINTS` are crashing - Fixes partly bevyengine#9021 (doesn't crash anymore, but the mesh is not correctly displayed) ## Solution - Only take up to `MAX_JOINTS` joints when extending the buffer (cherry picked from commit b28f633)
# Objective - Meshes with a higher number of joints than `MAX_JOINTS` are crashing - Fixes partly bevyengine#9021 (doesn't crash anymore, but the mesh is not correctly displayed) ## Solution - Only take up to `MAX_JOINTS` joints when extending the buffer
Bevy version
main on fd32c6f
What you did
I tried to import a glTF file derived from blender's Snow.
What went wrong
Bevy crashes with this wonderfully cryptic error and not much more information:
Why it happens
Under certain conditions (I'm still trying to find them out), an
Entity
will have aSkinnedMesh
component, but theSkinnedMeshInverseBindposes
asset forinverse_bindposes
Handle
will not exist.This causes
SkinnedMeshJoints::build
to returnNone
:bevy/crates/bevy_pbr/src/render/mesh.rs
Line 239 in 982e337
When it returns
None
,extract_skinned_meshes
will not add theSkinnedMeshJoints
to the render-world-extractedEntity
as per:bevy/crates/bevy_pbr/src/render/mesh.rs
Lines 288 to 293 in 982e337
This is problematic, because the
Entity
in question will regardless have aHandle<Mesh>
with skinning vertex attributes. Bevy's renderer checks those attributes to chose the bind group layout and shader for rendering the mesh:bevy/crates/bevy_pbr/src/render/mesh.rs
Lines 666 to 668 in 982e337
(this is called by the Prepass and
MeshPipeline
)But lo! the
render
impl ofSetMeshBindGroup
needs theSkinnedMeshJoints
component, and its index, to comply with the bind group layout required by the skinning shader variant:bevy/crates/bevy_pbr/src/render/mesh.rs
Lines 1228 to 1233 in 982e337
Now, we have a mismatch in bind group layout! And we get the wgpu panic.
Suggested improvements
extract_skinned_meshes
whenSkinnedMeshJoints::build
returnsNone
. Since it will lead to a panic regardless, at least make it explicit why it panics.error!
log, but not sure how an implementation would look like.The text was updated successfully, but these errors were encountered: