Repository: CesiumGS/cesium

Issue #12251: Rendering error for certain GeoJSON at south pole
Created: 2024-10-13T13:43:55Z
What happened?
CesiumJS bails out with a
RangeError: Invalid array length
    at PolygonGeometryLibrary.subdivideRhumbLine (http://localhost:8080/Build/CesiumUnminified/Workers/chunk-L63KAE7U.js:338:20)
    at createGeometryFromPositions (http://localhost:8080/Build/CesiumUnminified/Workers/createPolygonOutlineGeometry.js:142:56)
    at PolygonOutlineGeometry.createGeometry (http://localhost:8080/Build/CesiumUnminified/Workers/createPolygonOutlineGeometry.js:482:26)
    at createPolygonOutlineGeometry (http://localhost:8080/Build/CesiumUnminified/Workers/createPolygonOutlineGeometry.js:528:41)
    at http://localhost:8080/Build/CesiumUnminified/Workers/createGeometry.js:152:29
    at async Promise.all (index 0)
    at async onMessageHandler (http://localhost:8080/Build/CesiumUnminified/Workers/chunk-5ODQSF26.js:60:22)

for certain GeoJSON data near the south pole.
Specifically, for a GeoJSON polygon with the coordinates
              [-160.0, -90.0],
              [-180.0, -90.0],
              [-180.0, -80.0],
              [-160.0, -80.0]

(inlined in the sandcastle below).
The problem is that here, numVertices will be NaN, because the rhumb.surfaceDistance above is NaN, because ... (several debugging steps deeper) ... the sigma1 and sigma2 here are both -Infinity.
(I think that whenever Math.log is called, one has to make very, very very sure that either the argument is not 0, or the downstream computation anticipates the possible -Infinity. This did not happen here...)
Reproduction steps
Open this sandcastle:
https://sandcastle.cesium.com/index.html#c=jVNdb5swFP0rFk9EoqbRqiojNKrE1ErTpk5LtZd5D665Sa0aX2SbVHTiv89AYJBm0nix7z0fvoaDQG0dOUh4BUNuiIZXkoGVVUF/dL2QBaKrM9SOSw2GBYs100yLTunAuk/cca/9zTQhLHB1CSxI/O4OuKsMZKgUCCdRsyDqOZoXR06rH9vC2LbbGc2tekE0AKXBEoyT0PNnjpXRCe5FksMu8YbJw32WLOmHJPu+XV2xgDStSXM8cdeP2Nn87N2Pp5+9yjhCi+4BC3Cmnox8KvtaKSe/oar34+UHkkA0udTczQ7vn1nxrvSNi+X1Jb2MyMVHv/yKzuCr/8NX/8KvJ/gcnpWTYtw2/aZbfLPp0nIM1T3gZ4u6TcwWKyOAKuR5OKRoQd0z6HBX6S4vJMxH4mJ4x31W6V/EUp7nU+Z6RnxDLB7xBG8W6yAKUutqBZth8FtZlGgcqYwKKY0dFKVqv0/8VIkXcFRYO3in8VSa5vJAZH5z5l8hQnFrPbKrlNrKNx+MTRp7/jtp+yKk3j8cwChet7Tn5eZL36SUprEvzysdonri5sT5Dw
Sandcastle example
(See above)
Environment
Browser: All
CesiumJS Version: 1.122
Operating System: All

This was originally brought up, with real-world data (quite literally "real-world data"...), at https://community.cesium.com/t/25mb-geojson-file-related-rangeerror-invalid-array-length/35754

Duplicate issue #4801: Geometry.splitLongitude crashing for polygon that crosses the poles
Created: 2017-01-03T16:17:02Z
Reported on the forum: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/O_LaBx1_1wg
ne_10m_admin_0_countries2.json.txt
For some reason this crashes in Sandcastle but not in the CesiumViewer.  It also doesn't crash when scene3DOnly = true
var viewer = new Cesium.Viewer('cesiumContainer');

viewer.dataSources.add(Cesium.GeoJsonDataSource.load('../../SampleData/ne_10m_admin_0_countries2.json'));
DeveloperError: normalized result is not a number
Error
    at new DeveloperError (http://localhost:8080/Source/Core/DeveloperError.js:44:19)
    at Function.Cartesian3.normalize (http://localhost:8080/Source/Core/Cartesian3.js:422:19)
    at computeTriangleAttributes (http://localhost:8080/Source/Core/GeometryPipeline.js:1901:24)
    at splitLongitudeTriangles (http://localhost:8080/Source/Core/GeometryPipeline.js:2058:17)
    at Object.GeometryPipeline.splitLongitude (http://localhost:8080/Source/Core/GeometryPipeline.js:2482:17)
    at geometryPipeline (http://localhost:8080/Source/Scene/PrimitivePipeline.js:135:38)
    at Object.PrimitivePipeline.combineGeometry (http://localhost:8080/Source/Scene/PrimitivePipeline.js:278:26)
    at combineGeometry (http://localhost:8080/Source/Workers/combineGeometry.js:12:41)
    at http://localhost:8080/Source/Workers/createTaskProcessorWorker.js:56:42

Closing comment (2024-10-14T12:50:59Z): Also reported in #12251 / https://community.cesium.com/t/25mb-geojson-file-related-rangeerror-invalid-array-length/35754