I created a custom gridPrimitive that uses cesium polylines to draw a grid with dynamic level of detail.
All works fine, except in one case, our web app has multiple tabs, and if the gridprimitive is rendered on a non-visible/non-selected tab at the startup, I’m getting the following exception:
An error occurred while rendering. Rendering has stopped.
undefined
RangeError: Invalid array length
RangeError: Invalid array length
at updateFrustums (http://localhost:8080/GeoC2/libs/cesium/Cesium.js:139928:36)
at createPotentiallyVisibleSet (http://localhost:8080/GeoC2/libs/cesium/Cesium.js:140079:13)
at render (http://localhost:8080/GeoC2/libs/cesium/Cesium.js:140493:9)
at Scene.render (http://localhost:8080/GeoC2/libs/cesium/Cesium.js:140533:13)
at CesiumWidget.render (http://localhost:8080/GeoC2/libs/cesium/Cesium.js:149935:25)
at Viewer.render (http://localhost:8080/GeoC2/libs/cesium/Cesium.js:155035:28)
at animLoop (http://localhost:8080/GeoC2/app/ui/globe/CesiumGlobe.js?_dc=1433343126082:806:35)
Note as you can see in the callstack, the exception occurs later in Cesium, not in my code.
However adding the following condition to check for the current number of frames rendered to the GridPrimitive update() method makes the problem go away, though I’m not really satisfied with it.
GridPrimitive.prototype.update = function(context, frameState, commandList) {
if (!this.show) {
return;
}
if (frameState.frameNumber<30) { // This hack fixes the problem, no more exceptions, and the grid displays fine after 30 frames of being invisible
return;
}
// more code…
}
``
I guess something in Cesium is not yet ready in the initial frames and thus we get the exception?
The number 30 was just the smallest I tried that worked, for example 10 frames is not enough and I still get the exception.