Causes for CesiumTerrainProvder.availability returning NULL

We are seeing that occasionally, the .availability method will return NULL. But this seems to be user-system dependent. We cannot reproduce it ourselves. This is a snippet of our code:

terrainProvider = Cesium.createWorldTerrain(); // Cesium World Terrain
availability = null;
terrainProvider.readyPromise.then(function(response) {
  availability = terrainProvider.availability;
});

The above code is executed when our JS file loads. Later, when we try to call a method on the ‘availability’ object, we find that is NULL.

It seems that for some users-systems, availability is always NULL. Do you know what the cause could be? In general, would you be able to list all of the potential causes of this object being NULL? I have reviewed your documentation but it is still not very clear to me and doesn’t explain why it would keep returning NULL for certain users.

That’s odd, is the terrain loading correctly for these users visually? But the availability is always null for them? Can you get any more information, like are there any failed requests in the network console? What browser and OS are they using?

I believe availability is computed from the layer.json that is initially requested, so if that request is successful I’d expect that the availability be defined (but I wouldn’t expect the terrain to work if that’s not defined).

Thanks Omar - is there a chance that this would happen on certain browsers…old versions of IE perhaps?

Unfortunately, it is not possible to get info from the user’s network console and we are not actually displaying the terrain visually - we are just querying specific lat / long points to get their elevation.

It is certainly possible that the combination of browser/OS could be triggering a bug here, but I’m not aware of any known issue that causes this.

Any information you can collect that to help reproduce and narrow this down would be great. If you’re not displaying the terrain visually, how are you verifying that the terrain is loading successfully? You can see in the source code this is where the availability is computed:

If the layer.json request fails for any reason, then CesiumJS cannot load this terrain/cannot get the availability. I would also ask the user to confirm they can access Cesium World Terrain on their network, like by loading one of these examples: https://sandcastle.cesium.com/index.html?src=Terrain.html.

We are not explicitly requesting any layer.json. Is this request made behind the scenes when calling Cesium.createWorldTerrain()?

Yes, the layer.json contains the metadata that CesiumJS requests when loading any terrain in the quantized mes format.

To be clear, is layer.json loaded when requesting the quantized mesh or when initializing the terrain using the Cesium.createWorldTerrain() call?

The following two snippets of code are identical:

var viewer = new Cesium.Viewer("cesiumContainer", {
  terrainProvider: Cesium.createWorldTerrain(),
});
var viewer = new Cesium.Viewer("cesiumContainer", {
  terrainProvider: new Cesium.CesiumTerrainProvider({
    url: Cesium.IonResource.fromAssetId(1),
  }),
});

Either way you load terrain, the layer.json is the entry point that is loaded before any tiles are requested.