Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing some special character in label will cause Cesium broken #9945

Open
ZenDay opened this issue Nov 30, 2021 · 1 comment
Open

Writing some special character in label will cause Cesium broken #9945

ZenDay opened this issue Nov 30, 2021 · 1 comment

Comments

@ZenDay
Copy link

ZenDay commented Nov 30, 2021

Sandcastle example: https://sandcastle.cesium.com/#c=bZCxboMwEIZf5cQSkJCdNBshqBIdK3Vo1cmLgSO1amxkH6S0yrvXQCNVbTbf5/87/bpROhgVntHBEQyeoUSvho69LiwWUb3MpTUklUEnouQgjDC1NZ4Ag7TaDA0pUuiZbJr4SxiA3vpArMmuO0vpKLyk2bPW2e4BTw7Rx9sUtkk6G1pWqDNYbADCD8pgI0S1u9tvVsb5FV/ZJZiXudNPj1ZPLzbG5BClUe5p0lisKsC96nrrCAanY8Y4YddrGRrxaqjfkVjt/bxojub8t5o3agTVHG9cA2otvQ8/7aD1s/pEERU5D/l/qrayUeb0NKLTcppjb7vicYWMsZyH8bZJ1upKuj+bvwE

Browser: Chrome 96.0.4664.55

Operating System: macOS 11.6

Using some special character like '\b' will cause Cesium Broken.

I found that the problem may be at file /Source/Core/writeTextToCanvas.js L46

    var ascent, descent;
    // Find the number of rows (from the top) until the first non-white pixel
    for (i = 0; i < length; ++i) {
      if (pixelData[i] !== 255) {
        ascent = (i / width4) | 0;
        break;
      }
    }

    // Find the number of rows (from the bottom) until the first non-white pixel
    for (i = length - 1; i >= 0; --i) {
      if (pixelData[i] !== 255) {
        descent = (i / width4) | 0;
        break;
      }
    }

    var minx = -1;
    // For each column, for each row, check for first non-white pixel
    for (i = 0; i < width && minx === -1; ++i) {
      for (j = 0; j < height; ++j) {
        var pixelIndex = i * 4 + j * width4;
        if (
          pixelData[pixelIndex] !== 255 ||
          pixelData[pixelIndex + 1] !== 255 ||
          pixelData[pixelIndex + 2] !== 255 ||
          pixelData[pixelIndex + 3] !== 255
        ) {
          minx = i;
          break;
        }
      }
    }

    return {
      width: metrics.width,
      height: descent - ascent,
      ascent: baseline - ascent,
      descent: descent - baseline,
      minx: minx - padding / 2,
    };

We DID NOT initialize ascent and descent as a normal number. When length is equal to 0, the value of ascent and descent would be undefined.
And we will return a object just like:

{
   height: NaN,
   ascent: NaN,
   descent: NaN
}

That would cause Cesium broken.

@ebogo1
Copy link
Contributor

ebogo1 commented Dec 6, 2021

Thanks for reporting this @ZenDay - this looks like a bug and we'll posted updates in this issue once we get a chance to look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants