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.91k stars 3.48k forks source link

Crash when viewing tiles #9273

Open Osurac529 opened 3 years ago

Osurac529 commented 3 years ago

I am getting this error using 1.73 when viewing tiles, have not tried a newer version but the end of the stack trace seems to look the same as the current code in github master. I believe the problem is related to this line of code and that 'command' is undefined:

https://github.com/CesiumGS/cesium/blob/6639c8f30a11587551e11f7cdfaa72068a88e33f/Source/Scene/Cesium3DTileBatchTable.js#L1371

TypeError: Cannot read property 'derivedCommands' of undefined

TypeError: Cannot read property 'derivedCommands' of undefined at Cesium3DTileBatchTable.addDerivedCommands (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:126807:37) at Batched3DModel3DTileContent.update (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:149720:24) at Cesium3DTile.process (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:175245:19) at processTiles (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:177942:16) at Cesium3DTileset.prePassesUpdate (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:177803:5) at PrimitiveCollection.prePassesUpdate (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:194115:19) at prePassesUpdate (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:280355:16) at tryAndCatchError (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:280452:7) at Scene.render (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:280521:5) at CesiumWidget.render (http://localhost:8080/node_modules/cesium/Build/CesiumUnminified/Cesium.js:294542:19)

Here is an example tileset that causes the problem: https://drive.google.com/file/d/1V0YqM08jo_8Q_zhnQ9J1R5myu84Ouf3o/view?usp=sharing

Load the tileset into cesium, look at it top down, use the 3D Tiles Inspector and set the Maximum Screen Space Error to zero and the error will occur.

Osurac529 commented 3 years ago

This is the same as https://github.com/CesiumGS/cesium/issues/9278, it makes sense because I also disabled backface culling and it started happening, I want to say more, it did happen without that change but much less frequently.

lilleyse commented 3 years ago

@Osurac529 I created a sandcastle based on your steps but I wasn't able to trigger the problem. Hopefully you can confirm whether https://github.com/CesiumGS/cesium/issues/9278 fixes the problems.

var viewer = new Cesium.Viewer('cesiumContainer', {
  //terrainProvider: Cesium.createWorldTerrain()
});

var tileset = new Cesium.Cesium3DTileset({
  url: 'http://localhost:8002/static/Desktop/tiles/tileset_geographic.json',
  backFaceCulling: false
});

tileset.readyPromise.then(function() {
    viewer.zoomTo(tileset);    
});

viewer.scene.primitives.add(tileset);

viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
var inspectorViewModel = viewer.cesium3DTilesInspector.viewModel;
Osurac529 commented 3 years ago

I tried 1.77 and I am still getting the same error. I didn't include the code in my original post which will help. It definitely has to do with setting backFaceCulling to false. Here is the code:

`var viewer = new Cesium.Viewer('cesiumContainer', { scene3DOnly: true, selectionIndicator: false, baseLayerPicker: false, timeline: false, infoBox: false, animation: false //globe: false });

viewer.imageryLayers.removeAll(false);

var showGlobeImagery = false;
var showGlobeTerrain = true;

if (showGlobeImagery)
{
  // add imagery
  viewer.imageryLayers.addImageryProvider(new Cesium.createWorldImagery({
    style : Cesium.IonWorldImageryStyle.AERIAL_WITH_LABELS}));
}

// Load Cesium World Terrain
if (showGlobeTerrain)
{
  viewer.terrainProvider = Cesium.createWorldTerrain({
    requestWaterMask : true, // required for water effects
    requestVertexNormals : true // required for terrain lighting
  });

  // Enable depth testing so things behind the terrain disappear.
  viewer.scene.globe.depthTestAgainstTerrain = true;
}

viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
var inspectorViewModel = viewer.cesium3DTilesInspector.viewModel;

var tileset = new Cesium.Cesium3DTileset({ url: "http://localhost:8080/Source/SampleData/tileset_geographic.json",
                                           backFaceCulling: false });

var tileSetEventListener = function() {
    tileset.allTilesLoaded.removeEventListener(tileSetEventListener);
    console.log('All tiles are loaded');

    // Adjust a tileset's height from the globe's surface.
    var heightOffset = 40.0;
    var boundingSphere = tileset.boundingSphere;
    var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
    var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
    var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
    var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
    tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);

    inspectorViewModel.performance = true;
    inspectorViewModel.picking = false;
    inspectorViewModel.showBoundingVolumes = true;
    inspectorViewModel.maximumScreenSpaceError = 36;        
    inspectorViewModel.toggleLogging();
}

tileset.allTilesLoaded.addEventListener(tileSetEventListener);

inspectorViewModel.tileset = tileset;
viewer.scene.primitives.add(tileset);

tileset.readyPromise.then(function(tileset) {
    var boundingSphere = tileset.boundingSphere;
    var range = 2 * boundingSphere.radius;
    viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0, -2.0, range));
    viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
}).otherwise(function(error) {
    throw(error);
});

var scene = viewer.scene;
var canvas = viewer.canvas;
if (!scene.pickPositionSupported) {
    window.alert("This browser does not support pickPosition.");
}

var entity = viewer.entities.add({
    label: {
      show: false,
      showBackground: true,
      font: "14px monospace",
      horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
      verticalOrigin: Cesium.VerticalOrigin.TOP,
      pixelOffset: new Cesium.Cartesian2(15, 0),
    },
  });

  // Mouse over the globe to see the cartographic position
  var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
  handler.setInputAction(function (movement) {
    var cartesian = viewer.camera.pickEllipsoid(
      movement.endPosition,
      scene.globe.ellipsoid
    );
    if (cartesian) {
      var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
      var longitudeString = Cesium.Math.toDegrees(
        cartographic.longitude
      ).toFixed(15);
      var latitudeString = Cesium.Math.toDegrees(
        cartographic.latitude
      ).toFixed(15);

      entity.position = cartesian;
      entity.label.show = true;
      entity.label.text =
        "Lon: " +
       // ("   " + longitudeString).slice(-7) +
        ("   " + longitudeString) +
        "\u00B0" +
        "\nLat: " +
        //("   " + latitudeString).slice(-7) +
        ("   " + latitudeString) +
        "\u00B0";
    } else {
      entity.label.show = false;
    }
  }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

  canvas.setAttribute("tabindex", "0"); // needed to put focus on the canvas
  canvas.onclick = function () {
    canvas.focus();
  };`