Reputation: 13
I am currently working on a GIS project hat has to be cross browser, mobile, multiplatform and omnipotent. Cesium does not work without WebGL, on some older browser and other minor exceptions, but i have to catch them all. I decided to swich to OpenLayers when Cesium can't be an option, OL works well on pretty much everything. As for now, I have a try catch for new Cesium.Viewer, and the catch starts OpenLayers, which worked pretty great until recently, when i started getting Cesium "out of memory" error.
Cesium docs on Developer Error stands: should never be caught; instead the calling code should strive not to generate it. Well how do get around to that striving ? Is there any reliable way of checknig whether Cesium will fire up properly, or do i have to try catch every single method i am calling to be sure it won't crash out?
Upvotes: 1
Views: 1338
Reputation: 12418
Certainly new Cesium.Viewer(...)
should be wrapped in try/catch, as it will throw Cesium.RuntimeError
if it can't initialize WebGL. Also, viewer.scene
has a renderError event that is raised when an error occurs inside the render loop (as the normal/automatic render loop cannot be wrapped in try/catch).
But of course, any call that allocates memory on the browser can potentially fail if the browser is close to being out of memory. Sadly there doesn't appear to be much warning of this in JavaScript. Cesium has been scrubbed pretty well to not allocate memory while rendering (re-using scratch variables with the result
parameters, etc.), but some actions like zooming in on high-res terrain will necessarily allocate some memory. Adding entities and new graphics primitives and stuff will allocate memory. You probably want try/catch while adding new objects to the view.
Also take a look at the viewerPerformanceWatchdogMixin.
Upvotes: 2