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

Crash in GltfPipeline when loading two viewers with models #7688

Closed
OmarShehata opened this issue Mar 28, 2019 · 16 comments · Fixed by #7796
Closed

Crash in GltfPipeline when loading two viewers with models #7688

OmarShehata opened this issue Mar 28, 2019 · 16 comments · Fixed by #7796

Comments

@OmarShehata
Copy link
Contributor

Reported on the forum. If you create two Cesium viewers, each with glTF models loaded in, you get this crash:

DeveloperError: sub-region exceeds array bounds.
Error
    at new DeveloperError (http://localhost:8080/Source/Core/DeveloperError.js:43:19)
    at getStringFromTypedArray (http://localhost:8080/Source/Core/getStringFromTypedArray.js:29:19)
    at http://localhost:8080/Source/Scene/Model.js:1601:30
    at Function.ForEach.object (http://localhost:8080/Source/ThirdParty/GltfPipeline/ForEach.js:47:29)
    at Function.ForEach.shader (http://localhost:8080/Source/ThirdParty/GltfPipeline/ForEach.js:342:28)
    at parseShaders (http://localhost:8080/Source/Scene/Model.js:1593:17)
    at Model.update (http://localhost:8080/Source/Scene/Model.js:4428:25)

Sandcastle

This only happens when the second viewer is not created immediately. So it seems to be some kind of race condition?

It's throwing this error because during model load, the buffer.extras._pipeline.source array has a byte length of 0.

It's certainly a less common use case, but given that we do have an official example of using two viewers I thought it was worth documenting.

@benjaminmur
Copy link

Any ideas ?

@hpinkos
Copy link
Contributor

hpinkos commented Apr 2, 2019

@benjaminmur no sorry, we haven't had a chance to investigate this yet. My guess is some object is being shared between the two viewers when it shouldn't be. If you have time to look into it, we would be happy to review a pull request! Otherwise I'm not sure how soon we'll be able to prioritize this.

@mramato
Copy link
Contributor

mramato commented Apr 2, 2019

This sounds like a pretty bad regression, do we know what version it popped up in?

We should probably tag this next release.

@hpinkos
Copy link
Contributor

hpinkos commented Apr 2, 2019

@mramato I wasn't sure if this ever worked, but it looks like it works in 1.49 but not in 1.50

@lilleyse do you know what changed between those releases? I'm labeling this next-release since it is a regression

@lilleyse
Copy link
Contributor

lilleyse commented Apr 2, 2019

We upgraded to the 2.0 version of gltf-pipeline then, so it makes sense that if something broke it would be during that release.

@benjaminmur
Copy link

Thank you for making this a priority !

It worked in 1.49 and we built some main features out of this capability.
If you think i can help in any way, let me know !

@hpinkos
Copy link
Contributor

hpinkos commented Apr 23, 2019

Also reported by @gunmiosb in #7766

See #7766 for a Sandcastle example

@mramato
Copy link
Contributor

mramato commented Apr 26, 2019

The Sandcastle example had issues of it's own, so I cleaned up a reduce standalone test case: http://localhost:8080/Apps/Sandcastle/#c=zVjbcuI4EP0VFy/DVHmMMYSQa60wyWxmSchCkq2pOA/CFqCJsShZhmRT+fdt2TgYX7gku6n1k9V9unXULbUuM8yVGSVzwpUTxSNzxSQ+DSbaXSgrf7HDpsk8galH+BdVebE8BT7qDVmLPSmHyhC7PlEjqU9cYgvKvAvPoTYWjKcBY+ywuQ9SwYOlkAWugzw6wYIsVJb3+vXI8mZv/IytCBqfztDyhoEXelRsTkB9yRzilgPuqsqY0NFYqIsRfI2ZyUFNmU9Do5N4RCbmAv6wV9OGnE3aZMQJ8cvfqkZN0/fr9Ub1QFXqdU3f02v7eiP2LjnETscEO9QbLX1eYjHWBOuBGHt+uVrbS8KnVNhjAOsJGWeumxKNp6nJ8XvUzbU07wG+vOhXjTyqoZNkR4xTAglaHe8NB0pDxie+Nk45/DOAOHIP4OU4TqqkEcU79gouqXgGh1F4tbBNia9hxykvQi0/D09kzmRGlsK3+B++/Sa0ScKHyVYCM5F5Bm2iJ/kFnGY6C+EUZk8wuaZPxO3TvyWjqtFMg/CTBPVt7EqAocO3RLxGv69voY3GLTi2H4lzFocjigtgXmW0ZKQiqicxVauEfZ8Iq7RC3iqNCKwguSSkxiqZ3U4HtZHxvXNzbpXUJHJGuA/RiHCGplulBTU17sG3wZnU66siX8rul75S0bNKHnBNg+JPXxU9ZELz8NZZnptMX/aYug4nXkF31VR3atoeqgGnT0X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This also only appears to be a problem for untextured models (at least groundvehicle loaded fine if I use that instead)

@benjaminmur
Copy link

Yes i confirm.

If you load a second viewer, with no timer, but with an untextured model, it crashes too !

Or, with timer and textured models.

@mramato
Copy link
Contributor

mramato commented Apr 26, 2019

Looking at the original Sandcastle example @OmarShehata has in his issue description, these look like two separate but related bugs. Not sure if it will be the same root cause but we definitely need to check both cases when we fix this.

@OmarShehata
Copy link
Contributor Author

OmarShehata commented Apr 29, 2019

This is a glTF caching issue. The note in this Model.js comment almost predicts this issue:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Model.js#L178-L189

To demonstrate that this is the issue, just add this line in Model.js:1393:

cacheKey += String(Math.random());

This fixes both issues presented above. When GltfPipeline loads a model, it actually edits the glTF object itself (for example here https://github.com/AnalyticalGraphicsInc/gltf-pipeline/blob/master/lib/addDefaults.js#L118). Two viewers loading the same model will interfere and this will manifest in various ways. To fix this, we could:

  1. Make the cache context specific, not global
  2. Keep the cache global, but have some kind of flag to simulate a mutex on the glTF?

I think 2 would be better, would use less memory, and would likely load faster. Assuming it's not too hard to have Model.js wait until the glTF being loaded finishes loading, since it's already set up to load resources across multiple frames.

@mramato
Copy link
Contributor

mramato commented Apr 30, 2019

Thanks for tracking this down @OmarShehata! 1 is definitely safer and probably easier, 2 looks trivial at a glance, but I wonder if it will just cause another edge case in the future. I don't have a strong preference either way.

@lilleyse
Copy link
Contributor

One fix is to not remove pipeline extras. This is what we did in 1.49 as well for probably the same reason.

@mramato's Sandcastle works now. @OmarShehata's has lighting differences though

lighting

@lilleyse
Copy link
Contributor

The lighting differences are fixed in #7796.

@cesium-concierge
Copy link

Congratulations on closing the issue! I found these Cesium forum links in the comments above:

https://groups.google.com/d/msg/cesium-dev/MjFBDuFwF28/AZGHfV15AwAJ

If this issue affects any of these threads, please post a comment like the following:

The issue at #7688 has just been closed and may resolve your issue. Look for the change in the next stable release of Cesium or get it now in the master branch on GitHub https://github.com/AnalyticalGraphicsInc/cesium.

@benjaminmur
Copy link

Thank you very much !

I've just try with the 1.57 Cesium version and it works just fine !

Thank you so much for solving this issue !

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

Successfully merging a pull request may close this issue.

6 participants