Link2 with GetRemainingPath causing Leak Detected logs

  • A* version: 5.3.1
  • Unity version: 6000.0.34f1

I’ve been using FollowerEntity and GetRemainingPath to generate a path preview of where the agent will travel in game. I recently added Off-mesh links and noticed a number of leak detected console logs. These seem to be the relevant parts of the stack trace:

0x000001502b6c0ceb (Mono JIT Code) Pathfinding.Collections.NativeCircularBuffer1<Unity.Mathematics.float3>:Clone () (at ./Packages/com.arongranberg.astar/Core/Collections/NativeCircularBuffer.cs:324) 0x000001502b6c0a83 (Mono JIT Code) Pathfinding.Funnel/FunnelState:Clone () (at ./Packages/com.arongranberg.astar/Utilities/Funnel.cs:439) 0x000001502b6c0233 (Mono JIT Code) Pathfinding.PathTracer:Clone () (at ./Packages/com.arongranberg.astar/Utilities/PathTracer.cs:1980) 0x0000014fc83a830b (Mono JIT Code) Pathfinding.FollowerEntity:GetRemainingPath (System.Collections.Generic.List1<UnityEngine.Vector3>,System.Collections.Generic.List1<Pathfinding.Util.PathPartWithLinkInfo>,bool&) (at ./Packages/com.arongranberg.astar/Core/AI/FollowerEntity.cs:1639) 0x0000014fc83a779b (Mono JIT Code) Pathfinding.FollowerEntity:GetRemainingPath (System.Collections.Generic.List1<UnityEngine.Vector3>,bool&) (at ./Packages/com.arongranberg.astar/Core/AI/FollowerEntity.cs:1594)

To replicate the issue:

  1. Setup getting started scene for recast graph up to ’ Ignore the agent when scanning the graph’
  2. Add a Link2 so that the agent can travel from the ground onto one of the boxes in the scene
  3. Add a script to the agent which will Debug.Log the GetRemainingPath Vector3 list result
  4. Play the scene and traverse the link
  5. Stop the scene
  6. Play the scene again

When the scene loads a second time is when I’m getting logs about detected leaks.

The script I’m using to output the path is:

using System.Collections.Generic;
using Pathfinding;
using UnityEngine;

public class AllocationTest : MonoBehaviour
{
    private FollowerEntity _followerEntity;
    private float _updateTimer = 0.0f;
    private List<Vector3> _path;
    private bool _wasPathLogged;

    void Start()
    {
        _followerEntity = GetComponent<FollowerEntity>();
        _path = new();
        _wasPathLogged = true;
    }

    void Update()
    {
        _updateTimer += Time.deltaTime;

        if (_updateTimer >= 1.0f)
        {
            _path.Clear();

            _followerEntity.GetRemainingPath(_path, out bool stale);

            _updateTimer = 0.0f;
            _wasPathLogged = false;
        }
        else if (!_followerEntity.pathPending && !_wasPathLogged)
        {
            foreach (var point in _path)
            {
                Debug.Log(point);
            }

            _wasPathLogged = true;
        }
    }
}

I’m pretty new to using Off-mesh links so I’m not sure if this is something I’m doing wrong or if I’m using GetRemainingPath in the wrong way. I’m using URP if that makes any difference.

What version of the Entities and Mathematics packages are you using? Followed those instructions and never got the leak on my end :frowning:

Maybe our off-mesh link structure is different?

The package versions I’m using are:

Entities - 1.3.8
Mathematics - 1.3.2

I wanted to check that it wasn’t just a problem locally, so I did a clean install of Unity on a different machine and tested with the same project and got the same console log about the leak.

I followed the same process of play the scene, move the target so that the agent travels over the Link2 and then stop the scene. Then when you play the scene again it appears as the first log in the console, or at least that’s what’s happening on my side. If the agent doesn’t use the Link2 then the message doesn’t appear.

I’ve uploaded the project that I’m using here: Leak test project

There will be compilation errors when you first open it as I deleted the A* package so that I’m not sharing the source files publicly. Restoring the package should resolve the errors.

Thanks for helping try to get to the bottom of this, I appreciate you looking into it.

That’s the big brain move :slight_smile:

I just checked the project and I’m getting it now- actually I think I might’ve been, I must’ve mistaken it for being a Warning or Error log rather than a standard information log. Very sorry about that! But I highly appreciate the test project anyways- I wouldn’t have noticed probably!

I’ll go ahead and tag @aron_granberg here (I am so sorry for spam tagging you buddy :sob:) I found some related threads but they seemed to have been fixed recently by upgrading Collections, and I have the latest version and are still having the issue so this might be novel.

Thanks. I managed to replicate it, and I will include a fix in the next update.

1 Like

That’s great news, thanks to both of you for getting this sorted so quickly.

1 Like