CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.97k stars 3.5k forks source link

Rendering error for certain GeoJSON at south pole #12251

Closed javagl closed 1 month ago

javagl commented 1 month ago

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

ggetz commented 1 month ago

I believe this is a duplicate of https://github.com/CesiumGS/cesium/issues/4801.

As a workaround, you can set scene3DOnly to true when creating the viewer to avoid this error.

ggetz commented 1 month ago

I'm going to close your issue to keep the discussion in one place. If you have any further input on this, please post it there instead.

javagl commented 1 month ago

I don't want to argue about what to close for which reason, but will mention a few points, at least for completeness:

Edit: