April 10, 2018 - Lightsaber VR dailies - plugging a leaky object pool

Leaky Object Pool

So, earlier today I posted a bunch of videos to catch the blog up to what I've been doing.
Today turned out to be a really great day for me because I plugged up a major memory leak of sorts which resulted in the object pool getting smaller and smaller. And there were probaby a few other bugs layered on top of it but I squashed them all so fast I'm not even sure what they were anymore.

A little more in-depth look at the shrinking pool:

After implementing a system for preallocating gameobjects for every procedurally cut mesh chunk, I ran into a problem where it appeared that after a while the pieces you were cutting were vanishing as soon as you cut them. This was due to the fact that my "getchunk" method could no longer find any unused objects so it simply "sacrificed" one that was already in use. I knew this was wrong because I could see in the project hierarchy that there were plenty available. Unfortunately I couldn't simply look at the pool array because it is a static class-level array which you can't see in the inspector even in debug mode... So, I did a lot of investigating and realized that I fell into the classic fencepost error trap which is to say the upper extreme of one loop was one short. This loop was shifting the values of the list so that the most recently used gameObjects were pushed to the back of the line and only the unused ones or older ones would be instantly available. Instead, what it did was shorten the list little by little until there would be only a couple left.

The video!

The end result can be seen in my latest play session where I literally filled up the platform with chunks of cut up objects with no sudden spikes. The frame rate did gradually drop to about 30fps around the 5 min mark. Looks like I managed to get it down lower around the 20s when the camera is facing the pile of chunks which leads me to believe I can optimize some more with the shaders and minimizing draw calls. I was pretty satisfied that this was an edge case. Granted, I still want to make my code run twice as fast but I think I'm getting a bit carried away...


Possible next steps:

Next on my list will probably be to have parts that are linked by joints come apart properly, i.e. the part closest to the parent joint should remain connected to it and lose the joint connection to its children while the part farthest from the parent joint should disconnect but take the children with it.
In its current state only the part closest to the parent joint stays hooked to the joint and the other part just falls away instead of taking the children which it should.

Some time later I'll look into skinned characters and chopping off ragdoll limbs, just to see how much more work it would take, I don't think that's the kind of game I'm making after all but who knows...

Comments

Popular Posts