-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 Material caching issue #2633
Conversation
Neither the `_loadedImages` or `_loadedCubeMaps` arrays were being properly populated when the image was already in the texture cache.
I'll also add that because of the race condition and current limitation of the |
Thanks @mramato. I'll look at this next week. |
Keeping image objects at this level of the engine is something we want to avoid. I plan on doing a system-wide texture cache/load pipeline soon so let's hold on this since it will replace it. |
How soon? There are users hitting this bug now and this seems like a simple interim fix. I agree that not having to cache these is the right solution, but if it's 3 months out, then I'm not sure what harm in doing this in the short term is (unless there are existing use cases where memory really does become an issue because of the cache). Ultimately it's up to you, just close this if you don't want it merged. |
Gunning for 1.10. We could also leave this open and make a decision mid-to-late May. |
Sounds fine with me. |
I assume this won't happened for 1.10? Will it definitely for 1.11? We can continue to hold off on this, I just wanted to know where we are at. |
Yes, 1.11 is likely. |
@pjcozzi I assume this isn't happening for 1.11? Should I update this branch so we can fix this issue in the short term, it's cropped up a few times on the forum. |
If I recall, this requires keeping a copy of each texture in CPU memory, right? This seems bad for those streaming textured buildings with custom geometries and Cesium materials, for example. Can you link to all the forum issues in this issue, and I'll have a look at them? |
The most recent one is: https://groups.google.com/d/msg/cesium-dev/Qhos2CpA1cY/Q2X_jTNDktUJ But the original is: https://groups.google.com/d/msg/cesium-dev/laVtluz3VRY/qjHdbUQ2Uj8J You are correct that we have to keep the texture around, but our approach to image based uniforms seems fundamentally broken otherwise, since you can never use the same texture more than once. Another possible solution would be to remove the Material texture cache completely, since I think that's where the problem lies. This should fix the bug but also prevent us from keeping around the source in memory. I'm not sure what benefit the cache provides in its current state. |
Sounds like the best solution for now. I can certainty fix these problems for real, but I can't commit to a timeframe. This would also replace #2843, right? |
Superseded by #2850 |
Yes, it replaces #2843 as well and also fixes a few new issues I uncovered in the process. |
Run the below code in Sandcastle, hit the first button, wait for it to load, then his the second button. In master the second polygon will be gray, in this branch both polygons will have the proper texture. The problem is that in master, neither the
_loadedImages
or_loadedCubeMaps
arrays are being properly populated when the image was already in the texture cache. In order to fix this I had to keep the source images around in the cache as well and add them to the proper collection when a cache hit occurs.There also appears to be a race condition in Material, which I'll write up a second issue for. Basically if you hit the buttons below quickly (or just add them both in the same function instead of having 2 buttons) everything works. This is because Material actually loads the same image twice, rather than keeping a promise to the image from the first request. Looking at the Material code, there are most likely additional bugs as well, we should really look into refactoring the entire object.