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.76k stars 3.46k forks source link

pickTranslucentDepth Crashes Cesium #11427

Open cyber-tomahawk opened 1 year ago

cyber-tomahawk commented 1 year ago

Sandcastle example: https://sandcastle.cesium.com/#c=bY9BSwMxEIX/SsipgmTxbLoI9VhQUDzlkmZHGzo7WTKTLVX872ZTUNHO7b33vWEmJGJRc4QjZLVWBEe1AY5lNC/NWzkdmt4kEh8JstNXt44chdb8UByAQH3W8nlLDZtlphgOz9kTY6la7mGSfaUkF/hmCkPzHysb6e0n1tfaspwQekeqzV0cp5RFlYwrYzqBcUIvwN2uhAOICczLYQtqu99VO8RZxWF94RMV0DPX5LUgPsV3cLq3XeX/VTH5oR74MENGf1qw/U2/PZvGGNtVebkpKeHO5z+bvwA

Browser: Chrome / Safari (assumed all)

Operating System: MacOS

Using the pickTranslucentDepth property of Scene crashes Cesium. https://cesium.com/learn/cesiumjs/ref-doc/Scene.html?classFilter=Scene#pickTranslucentDepth

Reproduction has (for me) been simple and consistent. In the sandcastle example all you need to do is zoom in, the error shortly follows:

https://github.com/CesiumGS/cesium/assets/62380558/3f1d85ad-13c0-40c9-b58a-b8861755b536

This is a critical bug as without pickTranslucentDepth enabled I can't use scene.pickPosition on transparent 3D tiles to get an accurate position.

An error occurred while rendering. Rendering has stopped. DeveloperError: This object was destroyed, i.e., destroy() was called. Error at new DeveloperError (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:10398:13) at Imagery.throwOnDestroyed (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:27463:13) at TileImagery.freeResources (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:200765:25) at GlobeSurfaceTile.freeResources (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:197114:22) at QuadtreeTile.freeResources (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:206323:17) at TileReplacementQueue.trimTiles (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:206358:20) at processTileLoadQueue (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:207186:37) at QuadtreePrimitive.endFrame (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:206648:5) at Globe.endFrame (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:207960:21) at render (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:227540:19)

ggetz commented 1 year ago

Hi @cyber-tomahawk, I am able to reproduce the error.

I can confirm that the error is caused by accessing resources which were destroyed in a previous frame. However, I think this is symptom of an issue processing globe tiles the frame after a pick when pickTranslucentDepth is true.

As another side effect, you can see the imagery flashing around the poles when zooming. That is very atypical behavior.

I'm not sure what the root cause here is yet. What is actually causing the globe tile processing issue will need some further investigation.

ggetz commented 1 year ago

@lilleyse Do you have any insight as to why setting pickTranslucentDepth may interfere with globe tile processing?

lilleyse commented 1 year ago

I'm not sure offhand. It might be worth doing a git bisect to see if this is a recent regression.

ggetz commented 1 year ago

In the meantime @cyber-tomahawk, would you mind elaborating on the reason pickTranslucentDepth is needed?

There may be possible workarounds, such as using drillPick or turning on pickTranslucentDepth before the needed pick, then off afterwards:

// picking the position of a translucent primitive
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
     scene.pickTranslucentDepth = true;
     const worldPosition = scene.pickPosition(movement.position);
     scene.pickTranslucentDepth = false;
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
cyber-tomahawk commented 1 year ago

I need to use scene.pickTranslucentDepth as I am working with Cesium3DTileset(s) that may have an opacity. Without pickTranslucentDepth enabled I'm not able to use scene.pickPosition on a tileset when it has an alpha colour value.

I can confirm though that toggling the property in a listener does work and no longer crashes the viewer when zooming in and out, thank you

ggetz commented 1 year ago

Also reported in https://github.com/CesiumGS/cesium/issues/11495.

ggetz commented 3 months ago

Also reported in https://github.com/CesiumGS/cesium/issues/12005.