cesium
cesium copied to clipboard
Label background is broken when use inputAction (unwanted gradient)
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:

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
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.
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
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.
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.
I also had this problem, changing the show property of the label and the background gradient would appear.
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:
- As mentioned in #10343, it looks like the problem introduced with #10275
- This line was introduced there: https://github.com/CesiumGS/cesium/pull/10275/files#diff-3994fd9c7fee18b809b5be3caa5fba1c3aff0b99d07ccfae0090dba24f4be835R57
- Because of the synchronous call, something changed, which broke the label background
- 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:
- The label gets created and no
_backgroundTextureAtlasis defined yet in theLabelCollection - This will make
LabelCollection.prototype.updatecreate a newTextureAtlasand then calladdWhitePixelCanvas - Then
LabelCollection.rebindAllGlyphsis called (back inLabelCollection.prototype.update) which will run intoif (!defined(backgroundBillboard))as thebackgroundBillboardis not yet created - This will then create a new
backgroundBillboardwhich references thewhitePixelCanvasIdthat is also used to initialize theTextureAtlas(that's a part I don't really understand) - At this point the previous call to
textureAtlas.addImageinaddWhitePixelCanvasmight 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 🤷) - The label is rendered with the correct background
- The label is hidden via
label.show = falsewhich ultimately somewhere (I don't know where) seems to clear the_renderedTextof the label (makes sense I guess :D) - I also guess, that this sets
_rebindAllGlyphsof the label totrue, because obviously the rendered text changed - Back in
LabelCollection.prototype.updatethis will now trigger another call torebindAllGlyphswhich creates a booleanshowBackgroundbased on the_showBackgroundproperty of the label (which is true) and based on if there is any rendered text (which is now false) - As
showBackgroundis false,label._backgroundBillboardis set toundefinedinrebindAllGlyphs - The label is now shown again via
label.show = true, which then does the same process, but now there is some rendered text again - As
showBackgroundis now true, butlabel._backgroundBillboardhas been set toundefinedbefore, we reach the same state as above in 4 (a newbackgroundBillboardis created). However, as the texture atlas is not reinitialized and the asynchronous call at the end ofaddWhitePixelCanvasis now done, something is different (I don't really know what). - 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 :)
Also reported in https://github.com/CesiumGS/cesium/issues/10974