cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Label background is broken when use inputAction (unwanted gradient)

Open xradiance opened this issue 3 years ago • 2 comments
trafficstars

Hi all, Can I get help with this problem, Is this a bug? As far as I know, it still happens 1.9 ~ later

You can see it in action in the attached sandcastle and in this screenshot: bug_label_background

Sandcastle example: https://sandcastle.cesium.com/#c=fZTdbuIwEIVfxZurILGm3b1LKdpumgq0EVSQbW8iVcYZwMLYke1A6Yp3Xzt/BUp7g+yZOd8Zjx2oFNqgLYMdKHSLBOxQCJoVG/xUxvzUo+U+lMIQJkClXucmFamgpZKJvDCnwhlVAGKWEwrRFoQZEpFxS6pMMCViS7RjlFqswYzc4o4aJoW/KES1AKftoH+pQKjyUmRvnWqMpiDAwjagCF6CeWR0PSX7SoZzqZmjOBuE2ML/VjeXwcIeIvMtq1PDEVJgCiXK0oP7ebdsOOe+Sy7ngHPr6Ujdk+Snnm1TXxrXKHsKWwwakyzz7USJgZjMgUcuvj9i3VTCQ/ez+Sf7HHAcPSQvYTwK/1S314wZfYGuu6yaPL7hurA+RFMftKtuleAOGjRnRcjAqwlQ6iXRLEm9bhPWZs8haNhlJzMXwg+jOH65G9+/TP4m8WgctQpZGG4nGkouVSssd/h5OEo+FD6zzKwCdN3G54Sul0oWIrvEmEb3782t5O53Wx0gowpok1tQhlHCJ4otmWgpTydhnEweW8VKKvbmvqRzzfAsgcNonETTVpizV+CTxcJ+LcHxVYREGbsi4od/1UXff151akn5ng7usg9e1+uXQx40tF9sk0tlUKG4j3HPwCbn9hXo3rygazCYal29K4T6vWNpP2NbxLLbC/8KiHKitc0sCs5n7A1Sb9Dv2foPUi5JxsRyYsfHyd6Vra4HcRXEGPd7dntZaaTkc6LOyP8B

Browser: Tested on Chrome 102.0.5005.115

Operating System: Windows 10

xradiance avatar Jun 16 '22 02:06 xradiance

Thanks for reporting this @xradiance. I think this is a bug. We addressed a similar issue in https://github.com/CesiumGS/cesium/pull/10343, but it looks like this can still occur when a new label is added. We'll take a look at this shortly since its a regression.

ggetz avatar Jun 16 '22 15:06 ggetz

Hi, as I've also experienced this again, I can share an even simpler sandcastle, just in case this helps :)
It seems to be enough to just hide the label and show it again to trigger the bug.

https://sandcastle.cesium.com/#c=bVLJTsMwEP2VUU6JFJwuUESbVtCABKISBxBccnGTaWvVsSvbaVnUf8d2E9b6EM28ecvESSGFNrBluEMFYxC4gww1qyvy7LEwDwrfZ1IYygSqPIhGuchF4ZWczpFb4cGBoDDMMNSElmX4kQuAjdQWkWLY+mZUGVtR0ScLJatrXCpEHZ6cn5Hu4LQ7GJzH0L8gF2c9d6LYmfiUIXhDAIOvZgh5MPPZO2ZWMKXFeqlkLco8iA+sBeM8k1yq72TXkensKrtvOHold9/SIRhVYzOaf8HHTF5u755uPHNvn/vDjWg0T6xCWZvQTcIIxpN2Z/8GxOXZy1pQrnHUrPBb5M4v4T+x23HUzvZxW/U6nU5TR6N2MYBTDzskiINUmzeOk1ZyyaqNVAZqxUNCEoPVhlP7bZJ5XazRkELrqElKk5/StGRbYOX4yL8BBada28mi5vyRvWMeTNLE8v9JuaQlE8uHLSpO3xxt1Z3MDiAhJE1se1xppORzqv44fwI

UniquePanda avatar Jul 29 '22 07:07 UniquePanda

Hi @ggetz,

do you have any updates on this? Unfortunately it's stopping us from updating Cesium past version 1.92 currently.

No pressure (I know there's enough stuff to do in this project), just wanted to know if this has been forgotten or if there is any plan to fix it. I had a look at the code myself but I think this is one of those problems that is hard to debug if you don't know the code already.

UniquePanda avatar Oct 04 '22 12:10 UniquePanda

This problem is persisting for me too, when initially drawing the label it works as intended and then the gradient appears when the label is updated.

kevinforrestconnors avatar Oct 04 '22 19:10 kevinforrestconnors

I also had this problem, changing the show property of the label and the background gradient would appear.

cuijindong avatar Oct 26 '22 09:10 cuijindong

I did some digging, but unfortunately I always get a bit lost in the code flow. There's much stuff going on regarding billboards and glyph rendering and I am definitely no expert on this, so I can't always decipher what Cesium is doing here 😄 However, based on what I understand and on what was mentioned in the issues, I at least found out some stuff.

Current state:

  1. As mentioned in #10343, it looks like the problem introduced with #10275
  2. This line was introduced there: https://github.com/CesiumGS/cesium/pull/10275/files#diff-3994fd9c7fee18b809b5be3caa5fba1c3aff0b99d07ccfae0090dba24f4be835R57
  3. Because of the synchronous call, something changed, which broke the label background
  4. That's why in #10343 this call was made asynchronous again.

However, it seems that making this asynchronous again, only moved the problem to a later time. So maybe the real problem lies somewhere else in #10275 (or maybe in another PR?). From what I saw in debugging, I have the following suspicion, although I don't know why it's happening. This is based on hiding and showing the label:

  1. The label gets created and no _backgroundTextureAtlas is defined yet in the LabelCollection
  2. This will make LabelCollection.prototype.update create a new TextureAtlas and then call addWhitePixelCanvas
  3. Then LabelCollection.rebindAllGlyphs is called (back in LabelCollection.prototype.update) which will run into if (!defined(backgroundBillboard)) as the backgroundBillboard is not yet created
  4. This will then create a new backgroundBillboard which references the whitePixelCanvasId that is also used to initialize the TextureAtlas (that's a part I don't really understand)
  5. At this point the previous call to textureAtlas.addImage in addWhitePixelCanvas might not yet be fully completed as it is asynchronous? (That's a suspicion and I don't know what implications that has on the rest of the code, but it looks like this is the case, although it feels like this should lead to some kind of exception 🤷)
  6. The label is rendered with the correct background
  7. The label is hidden via label.show = false which ultimately somewhere (I don't know where) seems to clear the _renderedText of the label (makes sense I guess :D)
  8. I also guess, that this sets _rebindAllGlyphs of the label to true, because obviously the rendered text changed
  9. Back in LabelCollection.prototype.update this will now trigger another call to rebindAllGlyphs which creates a boolean showBackground based on the _showBackground property of the label (which is true) and based on if there is any rendered text (which is now false)
  10. As showBackground is false, label._backgroundBillboard is set to undefined in rebindAllGlyphs
  11. The label is now shown again via label.show = true, which then does the same process, but now there is some rendered text again
  12. As showBackground is now true, but label._backgroundBillboard has been set to undefined before, we reach the same state as above in 4 (a new backgroundBillboard is created). However, as the texture atlas is not reinitialized and the asynchronous call at the end of addWhitePixelCanvas is now done, something is different (I don't really know what).
  13. This difference makes the label background appear with the gradient.

As I said, this is just a suspicion, because there are too many code parts, I don't understand. However, when you reinitialize the texture atlas every time label._rebindAllGlyphs is true in LabelCollection.prototype.update, the label background always looks correct. This means when you call the same block of code, that is called above in the if (!defined(this._backgroundTextureAtlas)). I highly doubt, that this is a valid solution, but it shows that there's some kind of connection to the texture atlas.

Sorry for the really long writeup, but right now I can't isolate the problem further. Could be a completely wrong direction, but maybe this helps someone who is a bit better with this specific code, to find a real solution :)

UniquePanda avatar Nov 17 '22 16:11 UniquePanda

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

jjhembd avatar Jan 02 '23 14:01 jjhembd