cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Cesium Map flickers when showing a model for the first time.

Open timeichfeld-msa opened this issue 1 year ago • 2 comments

What happened?

Hello,

I added a model via CZML and played the animation through the timeframe. When the ModelGraphic appears on the surface, the entire map blinks out. Sometimes it takes .25 seconds or more for the map to come back. It is very noticeable.

This did not happen in the last version 1.120 It is happening in 1.121 (October release)

During animation, when many hundreds of models are added to the map, all at close timeframes, it creates a strobe effect. The map flickers for each item initially placed on the map. Once the item is on the map, it does not flicker.

Please play through the sandcastle example an dlet it loop a couple times. you will need to reload th emap to reproduce the effect. (click 'run' again)

Reproduction steps

  1. navigate to Sandcastle Example
  2. Run the animation.
  3. When the modelGraphic is first shown on the map, the entire map dissappears for a moment.
  4. Once the item has been shown on the map, the map does not flicker when the model dissappears and reappears on the map. (loop or use the time controls). ...

Sandcastle example

sandcastle

Environment

Browser: chrome (any) CesiumJS Version: 1.121 Operating System: windows

timeichfeld-msa avatar Oct 04 '24 21:10 timeichfeld-msa

Thanks for the report @timeichfeld-msa!

Just to clarify, I see the blink in version 1.122, but not 1.121. Is this the same on your end? Or are you indeed seeing this in 1.121?

ggetz avatar Oct 11 '24 18:10 ggetz

Hi Gabby, yes, sorry about that, I see the flicker in 1.122, not 1.121

Thanks much :) -Timothy

timeichfeld-msa avatar Oct 16 '24 13:10 timeichfeld-msa

As pointed out in https://github.com/CesiumGS/cesium/issues/12261, this appears to be due to the label, not the model itself.

For instance, id I comment out the label property in the CZML, the issue does not appear.

ggetz avatar Oct 25 '24 13:10 ggetz

As pointed out in #12261, this appears to be due to the label, not the model itself.

For instance, id I comment out the label property in the CZML, the issue does not appear.

It is OK with one label, and flashes when there are more than two

netcanol avatar Oct 27 '24 09:10 netcanol

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

ggetz avatar Nov 08 '24 16:11 ggetz

As pointed out in #12261, this appears to be due to the label, not the model itself.

For instance, id I comment out the label property in the CZML, the issue does not appear.

yes, when only add an entity with label, the problem will appear

edgexie avatar Nov 11 '24 01:11 edgexie

I have this tagged as "priority - next release" since it is a regression we'd like to see get fixed ASAP. Unfortunately we have not gotten a chance to get to the bottom of it just yet.

I'll leave the label so this issue does not get lost; but at this point it's unlikely we'll get a fix into the next release on Dec 2. CC @jjspace

ggetz avatar Nov 21 '24 16:11 ggetz

Seems to be fixed with latest update (1.124.0) at least that's the case on my side

pakb avatar Dec 03 '24 08:12 pakb

Seems to be fixed with latest update (1.124.0) at least that's the case on my side

it's still not work with 1.124.0,,when click load data bottom, the sky still flickers! https://sandcastle.cesium.com/#c=bVJdi9swEPwri/tiQyJfj3soji+Uu7610EJKn/yyljapiCwZfeR6LfnvlSznkpAz2Eg7OzujkbnRzsNB0gtZeARNL/BMToaB/ZpqZVfwaf9stEepyXZFtep0p/nENKOXcRGp/zoNwHEgi808kDlOmlguLjKuD+hu8FSM+HEavEEtODqviKEQP41RPdqn4L3R0Y0yKECgx65YwDZonvShrJJ+tpTAjQmW0w9rBukompv1zpBLs8tkaT7u10F9eUNZUplQgK5grN7gMCpKDfV+UPUWuVTSS3IXSxaRaCqz5lymXRW/1epYrYpF0Tr/qmidmwA+y2E01kOwqowynqIM+ji2D3xPnnHnUtq5+YPPWeSo89Mj3++sCVo0YHc9lg/3Czi9d+zTmQ0wxiNLvWvgYfxzUe6NFWSXFoUM7ho83khLPQZ/aeBA1kuOaolK7nQDgxRC0a3q0puxgfsr5RPUm3i5wzU6S7f1ZWCtkAeQ4vGdnxK4Qucisg1KbeRf6op1W8f+G2q626j6PTpX+Jrafn9cf8tFxlhbx+37zDmESDm5PJk8d/8H

netcanol avatar Dec 26 '24 06:12 netcanol

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

In Cesium v1.125, when creating labels, the globe briefly disappears and reappears, causing a black flickering. I have created a very simple test in Sandcastle that demonstrates this effect: https://sandcastle.cesium.com/#c=dVFBTsMwEPzKKpcmUuWkghNNKyAcK3FoxSkX19kUC8eO7E1KQfwdJ05RBeWy9o5nZsdaYbQj6CUe0cIKNB6hQCe7hr2MWFxGYuwLo4lLjbaMkmWpS62QQPE9KjfoOqVGdMt1JbgjhYxX1c4Ytef2sSMy2lvt0FEZzaHutCBpNMQJfJYaQNYQB7MJgCkTcwI1stbKRpLs0TGLjenxzF4O5K+h/GT5T+jzxBf/2wz8wiiFY5Q4CV7BZiRPQVrj5Bj27iwtuCV/4/qG1dY0T3iwiC7O5nCbMV8XWebPZB70hO/ktbOH4D0bEw/DfInmUe7opHAduAD3smmNJeisihlLCZtWcT8t3XfiDYkJN30aIE8vpXkle5DV6srCQCjunH+p/Zq28gPLaJ2nnv9HqgyvpD4892gVPw2018V6E0DGWJ769rqSwqp/OX8D Pressing the Test button destroys and creates a label. The label does not flicker, but the globe does. This did not happen in Cesium v1.108.

I am testing on the latest version of Chrome on different Windows machines with different graphics cards and it fails on all of them. It also fails when using the entity API.

In this second example, you can see that the problem occurs when the first label is added to a LabelCollection: https://sandcastle.cesium.com/#c=jVLLTsMwEPyVJeKQQHEawYmmFVCOSEiAOOWAm2xbC8eO7E14VP137DjljcQhiXc9MzsZu9TKEnQCn9DAFBQ+wRytaGt23/fiIir7eq4VcaHQFFEyKVShJBJIvkBpPa+Vsu/eclWV3JJExqvqTmu54OaiJdLKSZ1XVeAU0QiWrSpJaAVxAptCAYglxHtBMvE1fOgHg8yWqJA1RtSCRIfWz4g/eb7y+LmWEnvlOPFWAfwTpHrCJog32op+/umOPueG3IqrY7Y0ur7ElUG08dHAlahWtIYDyMYjOBkz987GY/dNRkGR8Jmc2kNvY3/zhXaYbR88austbZN/hHWDFunPoIachn/5Kx+Dte5wB558S3U4NWeqtxSNotzSi8RZwAGcibrRhqA1MmYsJawbyV1E6aItH5FYad9F8/QzNa9EB6Ka/nJ7oJTcWrezdNNvxSsW0SxPHf4HVWpeCbW67tBI/uJh62x2FZqMsTx15e9MClF+U34D Press the "Add Label" button to add labels and the "Reset" button to clear the label collection. It only flickers when adding the first label.

ggetz avatar Jan 13 '25 15:01 ggetz

Thanks Gabby. I didn't see https://github.com/CesiumGS/cesium/issues/12231. I hope my examples are helpful for fixing this problem.

AndresPozo avatar Jan 13 '25 15:01 AndresPozo

Half an eternity ago I assisted in a similarish bug. I spent some time trying to track this down again and while I cannot offer a solution, I have a strong suspicion. We do not use the highlevel Cesium features but go directly for a LabelCollection. By strategically removing code fragments I could track the issue through packages/engine/Source/Scene/LabelCollection.js (function repositionAllGlyphs) into packages/engine/Source/Scene/TextureAtlas.js.

Here, I nearly gave up. Removing the framebuffer._bind() to framebuffer.destroy() did not help the issue one bit and that was the only thing I could think of which would cause the observations. However, removing the framebuffer allocation as well seems to solve the issue (although it breaks any LabelCollection or IconCollection which needs to resize). These are lines 213 to 222 in the current GitHub state although I could only test it in our slightly modified fork.

The cause seems to be the same as last time: resizing the atlas uses framebuffers, binding the framebuffers breaks the bindings of the scene-relevant framebuffer and that frame ends up all black. I'm unsure why this has happened suddenly during that monthly release. It probably only affects labels this time because the label SDFs have the only relevant use case for addImageSync. I'm slightly puzzled what happened there since even the Framebuffer constructor alone screws this up or why this has started happening suddenly (TextureAtlas at least did not seem to have had relevant changes for a long time).

I'm not sure I'm willing to spend another day digging through this but maybe someone with more experience in the area can fix that much quicker than me anyway.

BitMaster1980 avatar Jan 14 '25 17:01 BitMaster1980

Well, packages/engine/Source/Renderer/Framebuffer.js does a _bind() during construction, so no surprise just constructing the object already causes rendering artifacts. But it has been doing that for the last twelve years as far as I can tell that, so something else must have changed.

I have now wrapped the offending lines (that block in TextureAtlas) in

    const gl = context._gl;
    const previousReadFramebuffer = gl.getParameter(gl.READ_FRAMEBUFFER_BINDING);
    const previousDrawFramebuffer = gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING);

and

    gl.bindFramebuffer(gl.READ_FRAMEBUFFER, previousReadFramebuffer);
    gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, previousDrawFramebuffer);

in my local code base and the issue appears to be gone. That is not really a solution but I'm running out of ideas how to track this further in large foreign code.

BitMaster1980 avatar Jan 15 '25 07:01 BitMaster1980

Thanks for the investigation @BitMaster1980! This is a huge help!

ggetz avatar Jan 15 '25 14:01 ggetz

For the record, the title of this issue is probably a bit misleading. The number of labels should be completely irrelevant. The issue happens whenever the TextureAtlas backing the LabelCollection needs to resize (not counting the initial resize to create it). You can hit that in a single label if it contains enough glyphs or never with any number of labels if the glyphs composing them fit into the initially allocated TextureAtlas.

BitMaster1980 avatar Jan 15 '25 20:01 BitMaster1980

Also reported in this thread https://community.cesium.com/t/label-adding-to-map-causing-screen-to-black-out/38187 which includes some debugging sandcastles which may be helpful

lukemckinstry avatar Jan 27 '25 15:01 lukemckinstry