Closed gamemachine closed 6 years ago
Ok so just to confirm. It looks like I can just add a static method to LodDataSeaFloorDepth that clears _depthRenderers and them marks stuff dirty like the add/remove methods?
Something strange going on I think is related to depth caches so just putting it here.
I start in one scene that has a large depth cache. Load into another that doesn't have one (with or without my added code to clear all depth caches). Start seeing odd behavior with waves. They aren't as large as they should be, but with the camera at the horizon I can see the correct size pop in, then abruptly go away as the camera moves to a more downward angle to the water. And the right size waves only pop in at a certain distance out.
If I start out in the scene with no depth cache, it's normal.
Hey, thanks for posting. So you have a scene that is always resident which has the ocean in it, then you load/unload various 'sub-scenes' with terrain etc in them? Does your cached depths live outside the sub-scenes like the ocean?
The way I would expect things to work in this scenario that the depth caches would be embedded in the scenes with the respective geometry. This way old depth caches are unloaded/destroyed with the scenes, and new ones add themselves as normal. Provided this works then there is no updating of caches - old cached depths are removed, and new ones are created. This would require that the 'old' stuff is removed before adding the new stuff, otherwise when the new cache populates it will include the old geometry. Do you have the depth caches in the sub-scenes?
Yes I keep the ocean always loaded with the rest of the game global assets, then load into and out of scenes that have terrain (or just ocean but those are still individual scenes).
Depth caches are set in the individual scenes. I noticed the behavior above so I added a method to clear the depth caches on scene load.
Now I just noticed I put that clear in the wrong place, it runs in Start on each individual scene load so it's going to just randomly run before or after the depth caches for that scene are set. But even so the behavior I'm seeing points more to corrupted data, ie there is no situation where what I'm seeing should happen. Seems logical that there is some data just not being cleaned up/released somewhere.
Hm I guess the deregister calls might get missed. I suppose this would mean either you're getting caches orphaned each time you unload a scene (these would pile up in the scene view, i assume this is not the case), or RenderOceanDepth.OnDisable() is not being called during unload, which would be disappointing. If thats the case i guess i better check all the other places I'm relying on this call!!
An interesting test would be to add log statements in AddRenderOceanDepth() and RemoveRenderOceanDepth(), perhaps at the end with this:
Debug.Log("ADD " + rend.gameObject.name + ", " + _depthRenderers.Count);
This should reveal fairly quickly if there are removes being missed.
I'm interested at looking at this myself but I have other issues that have been waiting for my attention for a while so I shouldn't dive into this immediately.
I can't think of any other data that would get stale, although its not impossible that there is.
The other bit of state is the existence or not of the command buffer to render the depths. I see LodDataSeaFloorDepth.RemoveCommandBuffers() is called from both OnEnable and OnDisable. Perhaps OnEnable is called after scene load, even if this GO is not in the scene!? That would be another surprise but could be worth a log statement.
Ok let me investigate it some more based on your feedback. I didn't really put a lot of time into debugging it yet got dragged away on other stuff.
Doing a pass closing stuff out. I'll close this due to inactivity and I haven't heard anyone else having issues here. Let me know if you do investigate further, can reopen if needed.
Looking at the best way to manage depth caches. I load the ocean once on game start and then change scenes now and then, at which point the depth caches need to be updated.
Ideally, I'd like to just generate all depth caches offline and have an api call to remove all and one for add depth cache.