Warlander / DeedPlanner-3

Village design and preview tool for Wurm Online and Unlimited
Apache License 2.0
23 stars 9 forks source link

Loading .MAP results in OutOfMemoryException on WebGL version #2

Closed PatrickDahlin closed 5 years ago

PatrickDahlin commented 5 years ago

Trying to load a map on the WebGL build lags hard and runs out of memory, when it finally responds only half the map is loaded.....

Warlander commented 5 years ago

Could you share the map please?

WebGL version running out of memory when trying to load very large maps is a known issue and primary limitation of the web version, but I can take a look and see if something can be done.

PatrickDahlin commented 5 years ago

I wouldn't call this a big map, hence it's odd it runs out of memory. Have you tried reducing the amount of objects in memory and/or batching them together?

deed_plan.zip

Warlander commented 5 years ago

I identified some memory problems already (and fixed few of them) and will take a look at remaining ones soon.

Most of current memory issues come from fact that most models and textures are stored both on CPU and GPU side, and in case of WebGL version is amplified by fact that more advanced texture memory optimizations available in standalone version aren't supported by WebGL. Making textures and models GPU-only will require some internal changes, but should lead to significant reduction of memory usage.

Warlander commented 5 years ago

I see WebGL-specific memory spike on your map peaking at 3 gb before it comes back to 1.6 gb. This is likely caused by how garbage collection in WebGL works, as explained here: https://docs.unity3d.com/Manual/webgl-memory.html

One distinction in WebGL, however, concerns the points in time when garbage collection (GC) can take place. To perform garbage collection, the GC would normally need to pause all running threads and inspect their stacks and registers for loaded object references. This is not currently possible in JavaScript. For this reason, the GC will only run in WebGL in situations where the stack is known to be empty (which is currently once after every frame). This is not a problem for most content which deals with managed memory conservatively and has relatively few GC allocations within each frame (you can debug this using the Unity profiler).

Currently loading of the entire map takes a single frame, so GC have no time to remove no longer used objects (including download cache). I will make it asynchronous, which should both eliminate memory spikes and improve overall user experience. :)

Warlander commented 5 years ago

@PatrickDahlin version 3.0.4 with fixes for the memory problems is out, could you check if everything is working on your side now?

PatrickDahlin commented 5 years ago

@Warlander It does load in the map now although slowly. I found some more bugs regarding rotation of some objects and missing bridges among other things but I will post a new issue when I get some more reference pictures to show the problem at hand.

PatrickDahlin commented 5 years ago

After trying it out a couple of times it seems that the loading halts at times with no visible error, just unresponsive ui.. Looking at the console I get an InvalidOperationException but no file/line to reference to.

warlander.github.io-1569489116927.log

Also, running from Edge (Was using chrome) it doesn't load at all. I'm getting an error that Texture2Darray isn't supported on this platform

Texture2DArray is not supported on this platform/GPU

(Filename: ./Runtime/Graphics/Texture2DArray.cpp Line: 119)

UnityException: Failed to create 2D array texture because of invalid parameters.
  at UnityEngine.Texture2DArray.Internal_Create (UnityEngine.Texture2DArray mono, System.Int32 w, System.Int32 h, System.Int32 d, System.Int32 mipCount, UnityEngine.Experimental.Rendering.GraphicsFormat format, UnityEngine.Experimental.Rendering.TextureCreationFlags flags) [0x00000] in <00000000000000000000000000000000>:0 

(Filename: currently not available on il2cpp Line: -1)
Warlander commented 5 years ago

InvalidOperationException is caused by TextMeshPro being unable to find embedded resources for localization support (which I'm not including in build to reduce the WebGL build size). This error on its own shouldn't cause any issues.

I'm unable to reproduce the halt issue, but I suspect what might be wrong and made a hotfix. Could you check if the problem still happens?

Is the message about not supported platform/GPU happening on the new Edge (Chromium-based) or on the old Edge? I have no plans to support IE and old Edge, especially given that Microsoft seems to move away from both of them in recent days and they lack WebGL 2 support: https://caniuse.com/#feat=webgl2

PatrickDahlin commented 5 years ago

Seems to be working again, it does take minutes to load the objects/buildings compared to sub-second time that deedplanner 2 has. Still I'm regarding this as fixed for now, as for the edge thing I'm running the latest windows update but I don't know if it's the "new" chromium edge or not...

Warlander commented 5 years ago

@PatrickDahlin DeedPlanner 2 rendering was using much less caching/batching, so map loading was nearly instant but rendering performance overall was much worse. In addition, web version of DeedPlanner 3 is using real-time model/texture streaming, so loading times are very network dependent. (your map takes about 2 minutes to load on my 8 mb/s connection)

I think the "old" Edge is still default in Windows 10, but this will likely change soon.