When I load another scene , (in runtime) I get the following error :
Could not terminate pathfinding thread[0] in 50ms, trying Thread.Abort
UnityEngine.Debug:LogError(Object)
AstarPath:OnDestroy() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1641)
I think I am not destroying / closing path finding thread correctly before I load the scene.
I think there’s some underlying problem there. I tried modifying the code to wait for 5000ms for each thread and I’m still getting this error (plus it takes forever to exit play mode since it waits 5000ms for each pathfinding thread).
I’m getting a random number of threads with this issue each time I run it, usually 5 or 6 and different numbers each time:
Could not terminate pathfinding thread[0] in 50ms, trying Thread.Abort
(the thread[0] can be any of thread[1] through thread[7] in my case)
Any ideas on how to fix this? I’ve commented that line out for now but it always feels wrong to terminate threads like that…
Any ideas on how to fix this? I've commented that line out for now but it always feels wrong to terminate threads like that...
Yes I totally agree. I am doing exactly the same thing. Just commenting it out at the moment… but I am pretty sure that can’t be the “solution”
Sorry for the late answer. I have had (and still have to some extent) a lot to do the last few weeks.
Yeah I think there is a bug at the moment where the pathfinding thread refuses to terminate gracefully, so that fallback code is executed. It shouldn’t be a problem for your games however, it’s just an annoying error message.
I will try to fix it for the next version.
You can call Interrupt just before the call to Join. It will inform the other thread to exit via an exception. You’ll need to add a check in CalculatePathsThreaded for that exception so it does not trigger another error message. Calling Join by itself does not necessarily let the other thread know it should exit which is why it was timing out for me.
There are other ways to handle this, but it is how I avoided that error message.
In file AstarPath.cs: public void OnDestroy () { ... threads[ i ].Interrupt(); if (!threads[i].Join (50)) { ... }
private static void CalculatePathsThreaded (System.Object _threadInfo) { ... catch (System.Exception e) { if (e is System.Threading.ThreadInterruptedException) return; ...
Hopefully this helps.
Yeah, but I don’t really want to use an interrupt.
There are some other flags which the threads check for, and those should make it exit gracefully. That isn’t happening right now however.
Sorry to dig out an old thread, figured better than making a duplicate…
I am getting the same:
Could not terminate pathfinding thread[10] in 200ms, trying Thread.Abort
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:LogError (object)
Pathfinding.PathProcessor:JoinThreads () (at Packages/com.arongranberg.astar@4.3.51/Core/Misc/PathProcessor.cs:260)
AstarPath:ShutdownPathfindingThreads () (at Packages/com.arongranberg.astar@4.3.51/Core/AstarPath.cs:1405)
AstarPath:OnDisable () (at Packages/com.arongranberg.astar@4.3.51/Core/AstarPath.cs:1427)
Unfortunately, this is happening between each level. I can ignore it for a while, but seemingly eventually leads to Unity editor stalling, forcing me to end task restart. Obviously the game can’t crash between levels. Any ideas how to exit gracefully?