Infinite loop in measureText.js under Firefox

Good afternoon all.

I want to share something with you.

I've found a weird behaviour in Cesium running under Firefox (51.0.1 32 bit). Sometimes it gets stuck in measureText.js, around line 173.

The code that causes the issue is:

for(i = 0; i < len && pixelData[i] === 255; ) {
   i += w4;

   if (i >= len) {
       i = (i-len) + 4;
   }
}
var minx = ((i % w4) / 4) | 0;

It's easy to reproduce the issue:

being

var w4 = 8;
var pixelData = [255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255];

Causes the previous code to enters into an infinite loop.

I'm not sure about the real cause of this problem. The fact is that the same app is running fine under chrome and MS Edge, but firefox is making the app hang randomly. Maybe this call is causing it returning corrupt or invalid data, but as I said I'm not 100% sure about it.

var pixelData = ctx.getImageData(0, 0, w, h).data;

Anyway I've replaced the previous code by this:

        var findMinXCoordinate = function () {
            for (var c = 0; c < w4; c += 4) {
                for (var r = 0; r < h; r += 1) {
                    var i = r*w4 + c;

                    if (pixelData[i] !== 255) {
                        return ((i % w4) / 4);
                    }
                }
            }

            return 0;
        };

        var minx = findMinXCoordinate();

Now it do not gets stuck but obviously when firefox decides to return invalid pixel data I get blank labels.

Does anyone observed the same issue? How did you get rid of it?

Best regards.

Hello,

I believe you’re running into this bug: https://github.com/AnalyticalGraphicsInc/cesium/issues/4918

I’ve added a link to your post so we can notify you when we get a chance to look into it.

Best,

Hannah