o3de / o3de

Open 3D Engine (O3DE) is an Apache 2.0-licensed multi-platform 3D engine that enables developers and content creators to build AAA games, cinema-quality 3D worlds, and high-fidelity simulations without any fees or commercial obligations.
https://o3de.org
Other
7.85k stars 2.21k forks source link

EMotion - Dragging actor with no skinning weights into the scene crashes the editor #18381

Closed HydrogenC closed 1 week ago

HydrogenC commented 1 month ago

Describe the bug Adding a fbx file into the editor and dragging it into the scene crashes the editor. Likely caused by EMotion gem, since removing the gem then the editor doesn't crash under such conditions. Perhaps related to #15902.
The Actor in EMotionFX gem doesn't support actor with only blendshapes but no skinning weights. The editor crashes when such Actor is put into the scene as a result. Models with blendshapes but without skinning should be tolerated by the engine.

Assets required Jinhsi_boneless.zip

Steps to reproduce Steps to reproduce the behavior:

  1. Create a new default project and put the given fbx file in the folder
  2. Create a default scene and drag the imported fbx into the scene

Expected behavior A actor corresponding to the fbx model is created in the scene

Actual behavior A transform gizmo appears up and instantly the editor freezes and crashes

Screenshots/Video If applicable, add screenshots and/or a video to help explain your problem.

Found in Branch main and development. The crash is likely to be related to the EMotionFX gem.

Commit ID from o3de/o3de Repository 2409 binary release development at e3775002a627843f59ac48108db362a175467c02

Desktop/Device (please complete the following information):

Additional context The related error in the log is:

<08:23:35> Trace::Assert
 D:\workspace\o3de\Code\Framework\AzCore\AzCore/std/containers/span.inl(165): (24660) 'const class AZ::RHI::StreamChannelDescriptor &__cdecl AZStd::span<class AZ::RHI::StreamChannelDescriptor const ,-1>::operator [](unsigned __int64) const'

<08:23:35> index value is out of range

The full logs: Editor.log error.log

HydrogenC commented 3 weeks ago

It seems that the issue is caused by EMotionFX Actors not accepting models with only blendshapes but no skin weights. Having no skin weights causes several assertion failures.

HydrogenC commented 3 weeks ago

Copied from what I have published in the Discord sig-content section.
The crash was directly caused by a couple of assertion failures.


In the function ModelLod::GetStreamsForMesh: https://github.com/o3de/o3de/blob/5dbc1edb86aab66082bee6d298b902cf0a73b5f5/Gems/Atom/RPI/Code/Source/RPI.Public/Model/ModelLod.cpp#L340-L344 layoutOut only get assigned if success is true, but a actor without skinning weights will be false for lack of certain buffers. https://github.com/o3de/o3de/blob/5dbc1edb86aab66082bee6d298b902cf0a73b5f5/Gems/Atom/RPI/Code/Source/RPI.Public/Model/ModelLod.cpp#L311-L315 So that layoutOut won't be assigned for actors without skinning and thus trigger a size mismatch assertion failure. https://github.com/o3de/o3de/blob/e8570f9d635c0abbf3d733d0524a3c0ae75d726c/Gems/Atom/Feature/Common/Code/Source/SkinnedMesh/SkinnedMeshInputBuffers.cpp#L239-L241 In other references to ModelLod::GetStreamsForMesh the code may assert for whether success is true, which also causes a assertion failure with actors without skinning. https://github.com/o3de/o3de/blob/5dbc1edb86aab66082bee6d298b902cf0a73b5f5/Gems/DiffuseProbeGrid/Code/Source/Render/DiffuseProbeGridFeatureProcessor.cpp#L1034-L1040


https://github.com/o3de/o3de/blob/5dbc1edb86aab66082bee6d298b902cf0a73b5f5/Gems/EMotionFX/Code/EMotionFX/Source/Mesh.cpp#L189 If the actor doesn't have skin weights, then maxSkinInfluences will be zero, thus failing the assertion.


https://github.com/o3de/o3de/blob/5dbc1edb86aab66082bee6d298b902cf0a73b5f5/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/ActorAsset.cpp#L209-L216 There isn't a null check for indicesBuffAssetView and weightsBuffAssetView, which would be NULL if there's no skinning, thus crashing the editor due to access to 0x0000000.

However, after I fixed the points stated above, the editor doesn't crash any more, but the actor cannot be rendered correctly. It flickers for an instance when the viewport is refreshed, and then disappears. I was interested in filing a PR to fix this, but since I'm not quite knowledgeable about the Atom architecture, I'm not capable of fixing this by myself.