decentraland / unity-renderer

Unity implementation of Decentraland Client
https://play.decentraland.org
Apache License 2.0
136 stars 93 forks source link

Debug physics breakdown at specific location #494

Closed pravusjif closed 3 years ago

pravusjif commented 3 years ago

If I spawn at -11, -11 and move a bit to wait for the surrounding scenes to finish loading, something breaks the character collisions and I can for through any collider... somehow this breaks other stuff as the NFTShapes in the Genesis Plaza gallery are not there when this bug is triggered.

Doing commit hunting I couldn't find when this was introduced (tried going way back and I can still reproduce it) so I'm guessing one of the scenes at that location is breaking the explorer...

Screen Shot 2021-05-24 at 14.10.35.png

Invalid worldAABB. Object is too large or too far away from the origin.

Invalid parameter pos in Collider.FetchPoseFromTransform because it was infinity or NaN
UnityEngine.StackTraceUtility:ExtractStackTrace ()
DCL.PhysicsSyncController:Sync () (at Assets/Scripts/MainScripts/DCL/Controllers/PhysicsSyncController/PhysicsSyncController.cs:32)
DCLCharacterController:LateUpdate () (at Assets/Scripts/MainScripts/DCL/Controllers/CharacterController/DCLCharacterController.cs:348)

Invalid AABB rkBox
UnityEngine.Bounds:ClosestPoint (UnityEngine.Vector3)
DCL.Rendering.CullingController/<ProcessProfile>d__26:MoveNext () (at Assets/Rendering/Culling/CullingController.cs:178)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

Invalid AABB *this
UnityEngine.Bounds:Contains (UnityEngine.Vector3)
DCL.Rendering.CullingController/<ProcessProfile>d__26:MoveNext () (at Assets/Rendering/Culling/CullingController.cs:180)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

Invalid AABB a

Assertion failed on expression: 'IsFinite(distanceForSort)'

Assertion failed on expression: 'IsFinite(distanceAlongView)'

Invalid worldAABB. Object is too large or too far away from the origin.
UnityEngine.Renderer:get_bounds ()
DCL.Helpers.Utils:GetSafeBounds (UnityEngine.Renderer) (at Assets/Scripts/MainScripts/DCL/Helpers/Utils/Utils.cs:580)
DCL.Models.MeshesInfoUtils:BuildMergedBounds (UnityEngine.Renderer[]) (at Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfoUtils.cs:18)
DCL.Models.MeshesInfo:RecalculateBounds () (at Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfo.cs:89)
DCL.Models.MeshesInfo:get_mergedBounds () (at Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfo.cs:53)
DCL.Controllers.SceneBoundsChecker:IsEntityInsideSceneBoundaries (DCL.Models.IDCLEntity) (at Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/SceneBoundsChecker.cs:183)
DCL.Controllers.SceneBoundsChecker:EvaluateMeshBounds (DCL.Models.IDCLEntity) (at Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/SceneBoundsChecker.cs:200)
DCL.Controllers.SceneBoundsChecker:EvaluateEntityPosition (DCL.Models.IDCLEntity) (at Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/SceneBoundsChecker.cs:178)
DCL.Controllers.SceneBoundsChecker:EvaluateEntityPosition (DCL.Models.IDCLEntity) (at Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/SceneBoundsChecker.cs:157)
DCL.Controllers.SceneBoundsChecker:EvaluateEntityPosition (DCL.Models.IDCLEntity) (at Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/SceneBoundsChecker.cs:157)
DCL.Controllers.SceneBoundsChecker/<CheckEntities>d__21:MoveNext () (at Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/SceneBoundsChecker.cs:64)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

https://images.zenhubusercontent.com/337227404/50991e27-57e0-44ec-a104-1a4a3ef4a093/2.mov

https://images.zenhubusercontent.com/337227404/6d203b3c-20d4-4102-98e7-ad347f6066d6/3.mov

pravusjif commented 3 years ago

Upon further debugging, the problem is in GENESIS PLAZA, apparently when the clouds start moving, something f*cks everything up:

VID 1: https://drive.google.com/file/d/18AdCqrKHAL7Qc9f3GXz7MPSF1hsP5J-5/view?usp=sharing

VID 2: https://drive.google.com/file/d/134CeNxVF80kO8V4txH6RzQmXcJXpJWrF/view?usp=sharing

pravusjif commented 3 years ago

Screen Shot 2021-05-25 at 21.17.32.png

Upon further experimentation, If I intercept the transform update mesage for entities being positioned super far away (pos magnitude 10k, 40k or more) I can detect the culprit entities.

Also, if in those cases we escape and avoid applying position + rotation + scale to the entity gameobject, sometimes the whole physics breakdown doesn't happen.

I'll keep investigating.

pravusjif commented 3 years ago

I concluded that what's happening is:

  1. The Genesis Plaza scene breaks due to unknown circumstances when loading the scene from far away
  2. The scene code crash somehow updates the position and scale of certain entities with very large values
  3. The enormous values in position and scale end up breaking Unity's physics sync

I implemented a PR with a fix to avoid the physics breakdown when messages with these kind of values appear.

pravusjif commented 3 years ago

We decided to cap the vectors on Kernel's end, PR: https://github.com/decentraland/explorer/pull/2394