Tried to call native directly. It crashes the game with same error even when the amount of peds is not big. Maybe it is necessary to call it directly in another way? That person is also me, just created two topics to collect more possible solutions for the problem.
Code of function:
private void CleanPedTasks(ref Ped[] peds_to_clean_task, int size_of_peds_array)
{
for (int i = 0; i < size_of_peds_array; i++)
{
if ( Function.Call<bool>(Hash.DOES_ENTITY_EXIST, peds_to_clean_task[i]) & !Function.Call<bool>(Hash.IS_ENTITY_DEAD, peds_to_clean_task[i]))
{
//peds_to_clean_task[i].MarkAsNoLongerNeeded();
Function.Call(Hash.SET_ENTITY_AS_NO_LONGER_NEEDED, peds_to_clean_task[i]);
}
}
}