Another dev story
Problem: Game crashes with out of memory when loading a specific mission. Even though there are still 10+gb of RAM free.
I try to reproduce it, but can't, it takes very long to load, but loads fine.
Mh why does it take so long to load. Profile the mission loading.
Mh it spends most of the time loading models from disk, because it recalculates the bounding sphere of objects.
That loading from disk, all goes into file cache, which could be causing the running out of memory.
Why is it recalculating the bounding spheres? All models have their bounding sphere in the p3d headers, it shouldn't need to load the actual model data itself and actually calculate it?
All Car and Tank types, have a hotfix bugfix in them.
When loaded, they enlarge the bounding sphere to 150%, to account for trailers with animated ramps, who's ramps don't themselves increase the bounding sphere (We don't have any of these in vanilla Arma 3, nor Arma 2 afaik, this might be a leftover from VBS? Also modern vehicles would use a animated bounding sphere, so the animation takes care of this).
Instead of just taking the bounding sphere it already knows from the p3d headers,
(We already pre-calculate that when the model is binarized, because its so expensive to do)
it instead loads all LOD's, and iterates over all vertices to find out which one is furthest from center.
That takes time to load the files from disk, uses up memory for caching (we only have 3gb max) and wastes quite a bit of CPU time (main thread churning through model vertices to calculate the sphere).
3 lines of code, to just multiply the bounding sphere we already have, instead of completely re-calculating it.
mission load time went from 30s to 21s and file cache churn is drastically reduced..