Cesium: Can't turn on shadows during viewer construction with Cesium OSM Buildings?

Created on 4 Sep 2020  路  5Comments  路  Source: CesiumGS/cesium

Here's a Sandcastle with Cesium OSM Buildings. Click the button to toggle shadows, works fine.

If you enable shadows in the viewer constructor, you get:

An error occurred while rendering.  Rendering has stopped.
DeveloperError: normalized result is not a number
Error
    at new DeveloperError (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:83:13)
    at Function.Cartesian3.normalize (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:2040:13)
    at Ellipsoid.geodeticSurfaceNormal (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:3606:23)
    at Ellipsoid.cartesianToCartographic (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:3699:18)
    at fitShadowMapToScene (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:267333:40)
    at ShadowMap.update (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:267565:9)
    at updateShadowMaps (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:282939:17)
    at updateAndRenderPrimitives (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:282962:5)
    at executeCommandsInViewport (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:282734:7)
    at Scene.updateAndExecuteCommands (https://sandcastle.cesium.com/CesiumUnminified/Cesium.js:282477:7)
category - graphics type - bug

All 5 comments

FYI, this only happens at certain times of the day (I just tried to reproduce and it didn't work). Basically you need shadows to actually be cast in the scene. I edited the original link to have the demo always crash.

This looks like a clear cut "something isn't initialized yet" bug which cascades into NaNs.

I've tracked this to be a bug in this condition https://github.com/CesiumGS/cesium/blob/master/Source/Scene/View.js#L322.
In fact is not very clear for me what the intention is, as the condition is difficult to read. The bug happens when commnadFar has a negative value.

Rewritting this condition to something like the below code fixes the crash:

(!(pass === Pass.GLOBE && commandNear < -100.0 && commandFar > 100.0) && commandFar > 0.0)

I would say the above fix is just a hack and I'm inclined to think the condition is not correct as it is, or at least it is difficult to understand what it does. However I don't feel very comfortable changing this code without more knowledge about what is the intention.

Maybe it could be rewritten in a friendlier and more understandable way if the current code is correct.

~Probably @IanLilleyT could give more insights about it.~ (sorry for the too fast git blame)

cc: @lilleyse

This is more for @lilleyse . I was the last one to modify this file, and may have even introduced a bug in the process (do we know when this bug started happening?), but I'm not familiar enough with the shadow mapping system to know if there are any downsides to your fix

Thanks for investigating this @jtorresfabra. That helped me narrow down the bug fairly quickly. I opened https://github.com/CesiumGS/cesium/pull/9172.

Was this page helpful?
0 / 5 - 0 ratings