CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
937 stars 295 forks source link

`GlobeAwareDefaultPawn` causes stall when `flyToGranularityDegrees` is 0 #1025

Closed j9liu closed 1 year ago

j9liu commented 1 year ago

This was discovered in https://github.com/CesiumGS/cesium-unity/pull/154. The code for computing the flight path of GlobeAwareDefaultPawn does not account for the case when flyToGranularityDegrees is 0. This results in a divide by zero error and an infinite for loop that stalls the editor.

https://github.com/CesiumGS/cesium-unreal/blob/8e65171bca1dbae5e57e60c9efa75f87f60ab0a9/Source/CesiumRuntime/Private/GlobeAwareDefaultPawn.cpp#L110-L112

For Cesium for Unity, we logged an error whenever FlyToLocation was called with flyToGranularityDegrees set to 0. Then, the function would return early. This should be done similarly in Cesium for Unreal. It may also help to log a warning if the user sets the value to zero.

csciguy8 commented 1 year ago

The original issue suggests a solution that involves safeguarding against invalid values and warning the user.

Here's a proposal for an alternate solution, let's remove the FlyToGranularityDegreesproperty completely.

Here are supporting reasons why:

The final solution would replace the logic that looks up the current position (_keypoints, AGlobeAwareDefaultPawn::_handleFlightStep) with the logic that initially generates the cached position (AGlobeAwareDefaultPawn::FlyToLocationECEF). The _keypointsmember will be removed completely as well as the FlyToGranularityDegreesproperty.

Comments and suggestions welcome! @kring @j9liu

kring commented 1 year ago

Thanks @csciguy8, that sounds reasonable to me. I wouldn't be concerned about executing a scaleToGeodeticSurface every frame. As you demonstrated, it's not very expensive at all.