Possible bug in ANavigationData::TickActor Repath management logic

Hello!

We noticed that there’s a bit of code within ANavigationData::TickActor that might be wrong

TArray<FNavPathRecalculationRequest> WorkQueue(RepathRequests);
if (WorkQueue.Num() > MaxProcessedRequests)
{
	UE_VLOG(this, LogNavigation, Error, TEXT("Too many repath requests! (%d/%d)"), WorkQueue.Num(), MaxProcessedRequests);

	WorkQueue.RemoveAt(MaxProcessedRequests, WorkQueue.Num() - MaxProcessedRequests);
	RepathRequests.RemoveAt(0, MaxProcessedRequests);
}
else
{
	RepathRequests.Reset();
}

If path request reaches the maximum limit allowed, the code deletes the extra requests (fine) but it never resets the RepathRequest’s array after copying it into the WorkQueue. It seems to us that the RepathRequest.Reset() line should always be called. Can you confirm it’s the case?

We want to double check with your team before we deploy the fix in our project.

Thanks!

[Attachment Removed]

Hi Bruno,

My apologies for the delay. Other duties and vacation had me out of the office for quite some time!

Are you seeing a specific bug in how this is removing repath requests? The work queue is getting created prior to adding the elements from RepathRequests, and this should end up that there are no unaccounted for requests after the respective removals. I do not believe we encounter this particular error log in FN, so there is a chance it is something odd under the hood we have just not seen ourselves.

From looking through the code, I believe what is there is correct. The WorkQueue is created with the items of RepathRequests. If the WorkQueue exceeds the limit of MaxProcessedRequests, we trim the WorkQueue to be MaxProcessedRequests which trims from the end of the array. Afterwards, we remove the MaxProcessedRequests from the head of the RepathRequests array. This should mean that WorkQueue has requests 0-999 and RepathRequests contains 1000-N. That seems correct to me as removing WorkQueue.Num() - Max ProcessedRequests from RepathRequests would possibly have duplicate requests in both arrays causing some requests to be processed twice.

It is quite possible I have overlooked something. But if you are seeing a particular case where this is causing an issue, I would love to know more details so we could look at that particular scenario in the code.

-James

[Attachment Removed]