Difficult to reproduce error: Null reference exception on Android devices

We’re talking about once every 6 hours or so rarely, and I’ve never been able to reproduce it in the editor.
I’m using A* Pathfinding Project with two threads. Sometimes, pathfinding just terminates, with this error:

06-29 11:19:21.328: I/Unity(21852): NullReferenceException: Object reference not set to an instance of an object
06-29 11:19:21.328: I/Unity(21852):   at Pathfinding.ThreadControlQueue.Pop () [0x00000] in <filename unknown>:0 
06-29 11:19:21.328: I/Unity(21852):   at AstarPath.CalculatePathsThreaded (System.Object _threadInfo) [0x00000] in <filename unknown>:0 
06-29 11:19:21.328: I/Unity(21852): UnityEngine.Debug:Internal_LogException(Exception, Object)
06-29 11:19:21.328: I/Unity(21852): UnityEngine.Debug:LogException(Exception)
06-29 11:19:21.328: I/Unity(21852): AstarPath:CalculatePathsThreaded(Object)
06-29 11:19:21.328: I/Unity(21852):  
06-29 11:19:21.328: I/Unity(21852): (Filename:  Line: -1)
06-29 11:19:21.328: E/Unity(21852): Unhandled exception during pathfinding. Terminating.
06-29 11:19:21.328: E/Unity(21852):  
06-29 11:19:21.328: E/Unity(21852): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 49)
06-29 11:19:21.338: E/Unity(21852): Error : This part should never be reached.
06-29 11:19:21.338: E/Unity(21852):  
06-29 11:19:21.338: E/Unity(21852): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 49)

Which indicates this line, line 2529 in AStarPath.cs in having a problem:

Path p = astar.pathQueue.Pop();

I tried building a version without threads. While I (obviously) never got this error in the non-multithreaded version, I did get another odd one where it would continually log errors like so:

Path Failed: Computation Time: 0.00ms Searched Nodes: 0
Path Number 11516

Again, this is very hard to reproduce.
Does anyone know what could possibly be causing this?

It works perfectly fine otherwise.


Hm… Try the latest beta version. I have fixed another possibly related bug that had to do with the path queue.
Multithreading race conditions are the worst kinds of bugs.

Thanks! I’ll give it a shot.
Time for another 6 hours of testing.

Good luck with that :smile: