Jump to content
dont_have_name

Potential memory leak in BIS_fnc_unitPlay?

Recommended Posts

Amateur mission maker here. I'm about to tear my hair out over this, so I'd greatly appreciate it if anyone more knowledgeable than myself could help me figure out if there's an error in my scripts or if the function BIS_fnc_unitPlay has a memory leak of some sort.

So I'm trying to make a silly mission for my buddies that involves units flying around in circles, sort of like superman. I figured the best/easiest way to do this was using BIS_fnc_unitCapture to record units walking through the sky on multiple large floating boxes I had set up in a circle, then deleting the boxes and using unitPlay on the units. The unit flies their circle, and upon completion begins another go with another unitPlay.

This method works wonderfully. The transitions are smooth, I can use disableAI "ANIM" as well as switchMove "HaloFreeFall_non" to make them even look like superman flying.

The only problem I've faced is that over time the server host's FPS slowly declines. With 10 units on a loop for 8 minutes I lose 20 FPS! Once I terminate the functions, delete the units, and clean up everything related to the scripts, the server stays at the lower FPS unit a restart. I don't know too much about memory leaks, but this sounds like one to me.

 

Here's the code I use to get a unit to fly the loop until they die:

flyingUnit1Movement.sqf

_unitPlayback = (/*too much data to paste here. It is the data copied from BIS_fnc_unitCapture*/);
flyingUnit1 switchMove "HaloFreeFall_non";
_handle = [flyingUnit1, _unitPlayback] spawn BIS_fnc_UnitPlay;
while {alive flyingUnit1} do {
    if (scriptDone _handle) then {
        terminate _handle;
        _handle = [flyingUnit1, _unitPlayback] spawn BIS_fnc_UnitPlay;
    };
    sleep 0.1;
};
terminate _handle;
_handle = nil;

The units themselves are all created in a separate script, here one unit's creation:

unitCreation.sqf

flyingUnitSpawnPoint = [22132,20857,0]; //Position close to where I want unit to fly
flyingUnitGroup1 = createGroup west;
"B_Soldier_F" createUnit [flyingUnitSpawnPoint, flyingUnitGroup1, "flyingUnit1 = this;"];
flyingUnit1 disableAI "ANIM";
flyingUnit1MovementHandle = execVM "flyingUnit1Movement.sqf";

I've searched the forums as well as google for anyone who had a similar issue, but I could find nothing. I've tried pretty much everything I can think of to fix it, such as using call instead of spawn and checking if the function is done based off time rather than scriptDone. Nothing I can think of works. If it turns out that unitPlay has a memory leak, I'll likely try using BIS_fnc_unitCaptureSimple and BIS_fnc_unitPlaySimple to see if those have the same issue, but due to how long it took me to get these 10 paths right and set up, I'd rather get an experts opinion first. Finally, for what it's worth, I did the math and the unitPlay function is called just under 36 times every minute.

 

If anyone can see were this frame loss issue is coming from in my code, please help me out! I hate to jump to claiming BIS_fnc_unitPlay has a memory leak, but I've run out of ideas!

 

Share this post


Link to post
Share on other sites

UnitCapture and UnitPlay are not really designed for multiplayer use.  Especially not multiple units for 10 minutes of playback.  How huge is your mission file?

 

You might try this workaround from the feedback tracker:

 

 

attaching the unit to a gamelogic and running the unitplay off that

 

Really the answer is to not use unitPlay for this kind of thing.

Share this post


Link to post
Share on other sites

The total size of the 10 scripts that run the movement is 608 KB. My mission.sqm is 262 KB. All of the scripts combined (minus sounds & images) is 1.13 MB.

And I forgot to mention that the FPS decreases both in single player and when hosted on a server. It's not exclusive to multiplayer.

The actual total time they will be running is dependent on how fast the players can shoot them, but before the players can there is a minimum time of just under 90 seconds. I realize that on an average run I'll probably lose about 5 frames overall, which will be annoying since the mission will continue on for longer after this ends, but I'd still really like to know if the issue is with me or with the function so I can at least attempt to fix it or use a different method.

Share this post


Link to post
Share on other sites

HOLY MOLY I LOVE YOU KYLANIA AND I LOVE YOU LARROW!

I implemented Larrow's version and stepped away for FOURTEEN MINUTES and when I came back it was still running at a smooth 60 FPS! 

I'll have to use my current method if it's running in single player, but Larrow's version runs perfectly on a hosted server which is where this mission will be played 99% of the time!

Thank you Kylania for linking me to that script and thank you Larrow for making it!

:D

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×