Closed foxcc2021 closed 1 year ago
Thanks for the bug report and suggested fix.
By the way ... creating threads to load models is good trick for reducing latency in a game. Another way to reduce latency is to convert the models to JMonkeyEngine's preferred format (j3o) at build time and then load the j3o instead of the glTF. And of course one can combine both tricks.
The expectation is that the glTF loader won't be used at runtime in a production game. Perhaps that's why the original author of GltfLoader
didn't worry about thread safety.
Apparently, CustomContentManager which handles Gltf extension loading is also not thread-safe. The defaultExtensionLoaders
needs to be made non-static as well.
A fix is submitted: PR #1886
I use multithreading to load gltf models, when loaded, all model materials are messed up.
After I debug GltfLoader, I found out that there may be threading issue in the GltfLoader. The variable "defaultMaterialAdapters" cannot be "static". This variable will be shared when all threads load materials from the model.
A simple way to resolve this issue is to remove the "static". Hope this helps. I use jme version: 3.5.2-stable![20220505173134](https://user-images.githubusercontent.com/93635496/166900456-62948438-1335-4563-99c0-0cdada11880f.jpg)