Polyline position wrong on iPhone

1. A concise explanation of the problem you’re experiencing.

Polyline positions are wrong on iPhone XS. (and maybe on all iOS devices, we think Android works fine)

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

This example slowly animates camera and on desktop it works smoothly. On iPhone XS you will see bad jitter on polyline position!

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var line = viewer.entities.add({

name : “Test line”,

polyline : {

positions : Cesium.Cartesian3.fromDegreesArrayHeights([-154, 60.4, 1, -154.0002, 60.4, 1]),

width : 2,

material : Cesium.Color.RED








3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

This prevents the proper usage of polylines on mobile. Totally critical bug for us!

4. The Cesium version you’re using, your operating system and browser.

Newest, Chrome on win10 and safari on iphone xs.

A better test case with link to sandcastle:

var farOrigin = 10000 * 1000; // If this line is changed to “var farOrigin = 10000”, also iPhone works ok!

for (var i = 0; i < 20; ++i)


var offset = i / 7.0;


polyline : {

positions : [new Cesium.Cartesian3( 0 + farOrigin, 0, farOrigin + offset),

new Cesium.Cartesian3(10 + farOrigin, 10, farOrigin + offset)],

material : Cesium.Color.BLACK





On Windows we get this image with 20 polylines:

image (5).png

But on iPhone XS the wrong image with only 4 lines:


By setting result.high = 0; in EncodedCartesian3.js the iPhone XS gets fixed!:o

Same modification fixes this issue:

My final solution for now: Modify shader by adding the following line:

vec4 czm_translateRelativeToEye(vec3 high, vec3 low)


vec3 highDifference = high - czm_encodedCameraPositionMCHigh;

if (length(highDifference) == 0.0) highDifference = vec3(0);

vec3 lowDifference = low - czm_encodedCameraPositionMCLow;

return vec4(highDifference + lowDifference, 1.0);


It is a bit unclear still why this happens, but I guess iPhone XS ends up having NaN values in the highDifference at some cases? And now the length calculation “notices” this.

Thanks for the additional test cases and for investigating a fix! Would you be able to open a pull request for this? Then we can have someone on the team review and determine if this is the right fix or if it reveals an underlying issue. Having a PR would help move this along faster.

I posted your findings for now in that distorted vertices GitHub issue. Feel free to add anything I missed there.