CesiumGS / cesium-native

Apache License 2.0
438 stars 215 forks source link

`SampleHeightMostDetailed` crashes for procedural ellipsoid tileset #994

Closed j9liu closed 4 days ago

j9liu commented 1 week ago

Unfortunately I don't think we tested this on our side when we merged #908. When I do SampleHeightMostDetailed in Unity it crashes with this stack trace:

0x00007FF92B9CB699 (KERNELBASE) RaiseException
0x00007FF873A9F0CF (CesiumForUnityNative-Runtime) [D:\a\_work\1\s\src\vctools\crt\vcruntime\src\eh\throw.cpp:82] _CxxThrowException 
0x00007FF8733B828E (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\CesiumGeometry\src\Plane.cpp:23] CesiumGeometry::Plane::Plane 
0x00007FF8733B81AF (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\CesiumGeometry\src\Plane.cpp:29] CesiumGeometry::Plane::Plane 
0x00007FF8730A3802 (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\CesiumGeospatial\src\BoundingRegion.cpp:425] CesiumGeospatial::BoundingRegion::_computeBoundingBox 
0x00007FF8730A29D0 (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\CesiumGeospatial\src\BoundingRegion.cpp:30] CesiumGeospatial::BoundingRegion::BoundingRegion 
0x00007FF872CB3C25 (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\EllipsoidTilesetLoader.cpp:117] Cesium3DTilesSelection::EllipsoidTilesetLoader::createBoundingRegion 
0x00007FF872CB3CBF (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\EllipsoidTilesetLoader.cpp:97] Cesium3DTilesSelection::EllipsoidTilesetLoader::createChildTile 
0x00007FF872CB55E5 (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\EllipsoidTilesetLoader.cpp:78] Cesium3DTilesSelection::EllipsoidTilesetLoader::createTileChildren 
0x00007FF872CD71F6 (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\TilesetContentManager.cpp:1095] Cesium3DTilesSelection::TilesetContentManager::createLatentChildrenIfNecessary 
0x00007FF872CDF762 (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\TilesetHeightQuery.cpp:317] Cesium3DTilesSelection::TilesetHeightRequest::tryCompleteHeightRequest 
0x00007FF872CDEF9C (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\TilesetHeightQuery.cpp:216] Cesium3DTilesSelection::TilesetHeightRequest::processHeightRequests 
0x00007FF872CAE46E (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\extern\cesium-native\Cesium3DTilesSelection\src\Tileset.cpp:400] Cesium3DTilesSelection::Tileset::updateView 
0x00007FF87200FDCA (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\Runtime\src\Cesium3DTilesetImpl.cpp:136] CesiumForUnityNative::Cesium3DTilesetImpl::Update 
0x00007FF871FC3DCA (CesiumForUnityNative-Runtime) [C:\Dev\cesium-unity-samples\Packages\com.cesium.unity\native~\Runtime\generated-Editor\src\DotNet\CesiumForUnity\Cesium3DTileset.cpp:755] DotNet_CesiumForUnity_Cesium3DTileset_Update 
0x000001B0FFE92404 (Mono JIT Code) (wrapper managed-to-native) CesiumForUnity.Cesium3DTileset:DotNet_CesiumForUnity_Cesium3DTileset_Update (intptr,CesiumForUnity.Cesium3DTileset/ImplementationHandle)
0x000001B0FFE922C3 (Mono JIT Code) [C:\Dev\cesium-unity-samples\Reinterop\Reinterop.RoslynSourceGenerator\Cesium3DTileset-generated.cs:113] CesiumForUnity.Cesium3DTileset:Update () 
0x000001B204617F58 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FF88CA5FB04 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\mini\mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007FF88C99E7A4 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3066] do_runtime_invoke 
0x00007FF88C99E93C (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3113] mono_runtime_invoke 
0x00007FF726D733F4 (Unity) scripting_method_invoke
0x00007FF726D52BF4 (Unity) ScriptingInvocation::Invoke
0x00007FF726D3BCF4 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007FF726D3BDE2 (Unity) MonoBehaviour::CallUpdateMethod
0x00007FF72682566B (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x00007FF72682CA3A (Unity) BehaviourManager::Update
0x00007FF726A4083D (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
0x00007FF726A269AA (Unity) ExecutePlayerLoop
0x00007FF726A26B36 (Unity) ExecutePlayerLoop
0x00007FF726A2D0E9 (Unity) PlayerLoop
0x00007FF7279A65E9 (Unity) PlayerLoopController::UpdateScene
0x00007FF7279A478B (Unity) Application::TickTimer
0x00007FF727DF9B0A (Unity) MainMessageLoop
0x00007FF727DFE3DB (Unity) WinMain
0x00007FF7291DE77E (Unity) __scrt_common_main_seh
0x00007FF92DD07374 (KERNEL32) BaseThreadInitThunk
0x00007FF92E15CC91 (ntdll) RtlUserThreadStart

You can test this from Cesium for Unity by following the SampleHeightTerrainDetailed example in https://github.com/CesiumGS/cesium-unity/pull/507#issuecomment-2380048726.

j9liu commented 1 week ago

This is resulting from the Plane trying to construct from a NaN normal and distance. I looked up into the stack trace and it turns out the bounding region of one child has a west / east value of inf, which is not great. The child tile ID also looks really big for some reason?

image

Part of me wonders if this code is infinitely creating children until it hits a point where the math doesn't work out -- in that case, it's happening because it keeps going down createLatentChildrenIfNecessary. Since the EllipsoidTilesetLoader is procedural, it makes sense that it can technically keep producing children, but maybe we need to mark an explicit point where it stops trying to recurse.