Lockups and unable to path randomly

Hello,

I’m using Version: 3.2.5.1, I’ve setup my agent using a CharacterController and AIPath.cs with Seeker.

7 out of 10 times it works as expected. However, 3 / 10 the AI will be frozen in place and unable to pathfind. Debug logs give no errors or warnings indicating what’s wrong. Scanning process reports completed at 70-200ms on load. The profiler doesn’t indicate any excessive load either. The AI just refuses to move. Sometimes after 10-20 seconds it will sort itself out and start working… others it never moves. Just stop/starting play mode usually fixes.

Settings: Grid Graph, node size 2, width: 112, depth: 80, scan on start enabled, cache disabled, multi threading enabled.

Attaching a debugger gives me:
System.Threading.WaitHandle.WaitOne () in /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Threading/WaitHandle.cs:334

AstarPath.LockThread (_astar=System.ArgumentException: ToString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.) in Assets\AstarPathfindingProject\Core\AstarPath.cs:1962

And most of the time appears to show:

AIPath.cs : Line 2042 //Wait until there are paths to process
pathQueueFlag.WaitOne ();

Also, in an unrelated to above, clicking “Generate cache” under “Save & Load” without first clicking “Save to file” causes unity to lockup and required the process to be killed.

And I cannot disable the feature “Save node data” as it keeps getting reset on play. (with cache startup disabled)

I’m using Unity 4.2.2 Pro.

Also, when it locks up like this, I see paths in debug log, but again AI isn’t moving.

Path Completed : Computation Time 3.00 ms Searched Nodes 0 Path Length 1
Path Number 1
Path Completed : Computation Time 2.00 ms Searched Nodes 54 Path Length 12
Path Number 2
Path Completed : Computation Time 1.00 ms Searched Nodes 315 Path Length 45
Path Number 3
etc.

I’d really like to use this, but it seems very unstable for me. I get a lot of lockups with trying to use it.

For example, click scan in inspector while using A* gameObject then try and click another object in scene. This often causes the unity to lockup. And I’m running into bugs/lockups on save&load settings. I’d be happy to purchase if it didn’t have these issues. I notice you say several times that issues have been fixed in beta or Pro versions. But I don’t want to risk buying with these issues if the free version doesn’t work for me.

Hi

The first issue is a Unity bug as far as I know. On some machines, starting coroutines in Awake will not work properly and will delay the start of it a (seemingly) random number of seconds. The solution is to move all calls to StartCoroutine (…) in AstarPath.Awake to AstarPath.Start ( I think there is only one ). fyi: this has been fixed in the beta version.

The lockups you are experiencing is something I haven’t heard before from any user. And it is especially weird because all the code that is executed during those events haven’t been changed in any substantial way during the last year, so it seems like bugs should have cropped up by now.

I really have no idea what it could be. The only things which I have encountered which cause lockups of Unity except infinite loops is threads which are not properly stopped. But threads are not started when not playing anyway so I am lost here.

Do you have a reproducible case where these lockups happen? If so, maybe you could zip up the project and send it to me to see if I can replicate it.

“AstarPath.LockThread (_astar=System.ArgumentException: ToString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.) in Assets\AstarPathfindingProject\Core\AstarPath.cs:1962”

This seems to be the debugger trying to find out what the parameter _astar was, and thus causing an exception because… well, what it says.

If the problems persist, I could let you try the beta version to see if the issues have been fixed in that version.

Hi Aron,

I did find on the forums about that bug, but in this case it doesn’t appear to be the problem. I’m using your code from the pack, AIPath.cs and it doesn’t seem to have coroutines in Awake(). Another suggestion was to toggle mutli-threading/disable it and neither solved the problem with the startup pause.

I’ll see if I can put together an example of in a test project. The really hard part is that it works as expected a good number of times. And that even when it’s not working, I get success messages in the logs. So it’s not easy as easy to reproduce.

Hi

Sorry for the late answer.
The coroutine is started in the AstarPath.cs script, not in the AIPath.cs script.