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

Fix loading of label background #11040

Merged
merged 4 commits into from
Jan 17, 2023

Conversation

UniquePanda
Copy link
Contributor

@UniquePanda UniquePanda commented Jan 17, 2023

Fixes #10461

This adds a new boolean parameter updateImageIndex to TextureAtlas.prototype.addSubRegion() which is false by default. If it is true, the _indexHash value for the given image id is updated to point to the index of the new sub region. Otherwise the index will still point to the region of the whole image (same behavior as currently).

This is needed because billboards create such a subregion, but wouldn't currently use this subregion in later calls to _loadImage which results in the problems described in the issue.

I am not really sure if my solution is good, because I am no expert on this topic. There are some open questions:

  1. Does this has any side effects, that I overlooked?
  2. Should the index be updated always (without the need for the updateImageIndex parameter)?
  3. Should there be a way to still access the previous region? Maybe two arrays are needed, a _indexHash and a _subRegionIndexHash?
  4. addSubRegion isn't used anywhere else (only by _loadImage() of Billboard.js). Should this be refactored in general somehow?

I didn't add/update any tests yet, because of those questions.

Longer description of what I think is the problem of the current code that is fixed by this PR:
An imageSubRegion for the billboard backgrounds is added to the texture atlas on the first load of a billboard.
Later calls will not add anything to the texture atlas, but will request the correct image by relying on the texture atlas' _indexHash.
In these later calls the index is retrieved from the texture atlas and then directly passed to completeImageLoad().
This function then uses this index to get the correct texture coordinates from the texture atlas. The problem is, that the image sub region is not taken into account anymore at this point.
The initial call, that added the sub region, is getting the index by calling TextureAtlas.addSubRegion() which returns a promise that resolves to the index. This is the index of the created subregion.
However, later calls will receive the index of the whole image, because the _indexHash will still point to the index of the image and not its sub region. That's why the background looks different then.

@cesium-concierge
Copy link

Thanks for the pull request @UniquePanda!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.

@ggetz
Copy link
Contributor

ggetz commented Jan 17, 2023

Thanks for the fix @UniquePanda! Good catch! I think this was an oversight in #10275. When we resolve the promise in addImage, we also update the image id hash. However, that was not done for image sub regions, hence the bug.

Given this is fixing that oversight, as well as that TextureAtlas is a private class and this is the only place where that method is being used, it should be safe to make this fix the default behavior. The additional parameter to the the addImageSubRegion method` can be removed.

@UniquePanda UniquePanda force-pushed the 10461-fix-label-background branch from 5972f18 to 21f89d0 Compare January 17, 2023 17:19
@UniquePanda
Copy link
Contributor Author

UniquePanda commented Jan 17, 2023

I think this was an oversight in #10275

Ah yes, makes sense. I was wondering, why the problem didn't occur before and had forgotten about that PR :)

I removed the parameter and the index hash is now updated always, when a sub region is added.
I also added one line to the tests to test that behavior. However, I wasn't able to get that particular test to fail, even if I randomly changed numbers in it. So for me the tests passes locally, but it does so always, regardless if the assertions are correct or not 😅
So you can either keep the line in and trust it (if the CI passes) or someone else should try if the test fails with changed numbers 😅

@ggetz
Copy link
Contributor

ggetz commented Jan 17, 2023

Another good catch @UniquePanda! That test was not properly calling the final expectations of that test. I re-wrote the problematic specs a bit so that the expectation are actually being executed. I also made a tweak to your new expectation so that we avoid calling private members of the class where possible because accessing private members makes tests more tightly coupled to the source code, and therefore more fragile.

If you could add a note to CHANGES.md mentioning the issue being fixed, and assuming my tweaks pass CI, this should be good to merge!

@UniquePanda
Copy link
Contributor Author

That test was not properly calling the final expectations of that test

Haha, I have to admit that confused me a bit. I actually started to change the test like you did, but then thought I might just don't understand what it was doing Thanks for fixing. 😄

I updated the CHANGES.md.

@UniquePanda UniquePanda force-pushed the 10461-fix-label-background branch from fc13d09 to c9b463e Compare January 17, 2023 19:27
@ggetz
Copy link
Contributor

ggetz commented Jan 17, 2023

There's some antiquated promise behavior in some tests, so it's good to get them cleaned up. 😄 Thanks again @UniquePanda, happy to get this fix in!

@ggetz ggetz merged commit c9d3dc3 into CesiumGS:main Jan 17, 2023
@UniquePanda UniquePanda deleted the 10461-fix-label-background branch March 13, 2023 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Label background is broken when use inputAction (unwanted gradient)
3 participants