• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Zootie · May 17, 2010 at 05:25 AM · pathfinding

How to troubleshoot a SIGBUS error?

I keep encountering a SIGBUS error when working with a simple pathfinding script. I've found the function giving me the problem but I'm not sure where to begin troubleshooting within.

The Unity Editor does not give me an error when I press Play. It returns the correct result in the Inspector.

But everytime I try to Build and Run the project, I get this error in Xcode:

NullReferenceException: Object reference not set to an instance of an object UnityScript.Lang.Array..ctor (IEnumerable collection) DijkstraPath.DijkstraPath (UnityEngine.GameObject source, UnityEngine.GameObject target, UnityEngine.GameObject[] nodes) [0x00000] DijkstraPath.Update ()

Here's the scripts to illustrate the problem.

a) The NavPoint.js script (modified version of AutoWayPoint from FPS Tutorial):

Make several empty object in your scene and tag them "Waypoint." Attach this script to them:

var tagName: String = "Waypoint"; // tag name for all nav points

static var navpoints : GameObject[]; // all nav points

static var kLineOfSightCapsuleRadius = 0.1; //radius of line of sight capsule used to check neighboring status //var layerMask : LayerMask; //public var hitinfo: RaycastHit;

//var allWaypoints: GameObject[]; var neighborNodes: GameObject[]; //define neighbor array for each navpoint var neighborDistance: float[];

var previousNode: GameObject; var previousDist: float = Mathf.Infinity;

function Start() { navpoints = GameObject.FindGameObjectsWithTag(tagName); RebuildNavPointList();

}

function Awake () { navpoints = GameObject.FindGameObjectsWithTag(tagName); RebuildNavPointList(); }

@ContextMenu ("Update NavPoints") function UpdateNavPoints () { RebuildNavPointList(); }

// Draw the navpoint lines only when you select one of the navpoints function OnDrawGizmosSelected () { RebuildNavPointList();

 for (var p : GameObject in neighborNodes) 
 {

         Gizmos.color = Color.green;
         Gizmos.DrawLine (transform.position, p.transform.position);

 }

}

function RebuildNavPointList () { navpoints = GameObject.FindGameObjectsWithTag(tagName);

 for (var point : GameObject in navpoints) {
     (point.GetComponent(NavPoint) as NavPoint).RecalculateConnectedNavPoints();
 }

}

function OnDrawGizmos() { Gizmos.DrawIcon (transform.position, "waypoint.tif"); }

function RecalculateConnectedNavPoints () { var connected = new Array();

 for (var other : GameObject in navpoints) {
     // Don't connect to ourselves
     if (transform.position == other.transform.position)
         continue;

     // Do we have a clear line of sight?
     if (!Physics.CheckCapsule(transform.position, other.transform.position, kLineOfSightCapsuleRadius)) {
         connected.Add(other);
     }
 }



// neighborNodes = connected.ToBuiltin(GameObject);
// neighborDistance = new float[neighborNodes.length];

 for (i = 0; i < neighborNodes.length; i++)
 {
     neighborDistance[i] = Vector3.Distance(transform.position,neighborNodes[i].transform.position);
 }

}

b) Then make another empty object and attach this script. Choose one NavPoint as the source node another NavPoint as the target node:

var tagName: String = "Waypoint"; // String used to tag all way points

var myWaypoints: GameObject[]; //all nodes var myPath: GameObject[]; var shortestPath: Array;

var nodes: Array;

var mySource: GameObject; var myTarget: GameObject;

function Start() { myWaypoints = GameObject.FindGameObjectsWithTag(tagName);

}

// All waypoints need to have the neighbors script attached, which stores neighborNodes/neighborDistance, and previousNode/previousDistance

function DijkstraPath(source: GameObject, target: GameObject, nodes: GameObject[]) {

 //initialize previousNode and previousDist values for each neighbor game object
 for (i = 0; i < nodes.length; i++)
 {   
     (nodes[i].GetComponent(NavPoint) as NavPoint).previousDist = Mathf.Infinity;
     (nodes[i].GetComponent(NavPoint) as NavPoint).previousNode = null;
 }


 //if the node is a source node it will get a previousDistance of 0

 (source.GetComponent(NavPoint) as NavPoint).previousDist = 0;

 //repeat until we visit every node in the graph and it is empty 
 while (nodes != null)
 {
     var bestNode: GameObject;
     var bestDistance: float = Mathf.Infinity;
     var bestIndex: int;


     for (i = 0; i < nodes.length; i++)
     {
         previousDistance = (nodes[i].GetComponent(NavPoint) as NavPoint).previousDist;

         //find node with smallest distance
         if (previousDistance < bestDistance)
         {
             bestDistance = previousDistance;  
             bestNode = nodes[i];
             bestIndex = i;
         }
     }   

     if (bestDistance == Mathf.Infinity) //only happens if there is no path to the source
     {
         break;
     }

     //remove this node from our list

     var nodeArray = new Array(nodes);
     nodeArray.RemoveAt(bestIndex);
     nodes = nodeArray.ToBuiltin(GameObject);

     var nlist = (bestNode.GetComponent(NavPoint) as NavPoint).neighborNodes;

     for (i = 0; i < nlist.length; i++)      
     {

         var neighborDist = (bestNode.GetComponent(NavPoint) as NavPoint).neighborDistance[i];
         var totalDistance = neighborDist + bestDistance;

         if (totalDistance < (nlist[i].GetComponent(NavPoint) as NavPoint).previousDist)
         {
             (nlist[i].GetComponent(NavPoint) as NavPoint).previousDist = totalDistance;
             (nlist[i].GetComponent(NavPoint) as NavPoint).previousNode = bestNode;

         }
     }   
 }

 if (target)
     var curNode: GameObject = target;

 var shortestPath = new Array();

 while ((curNode.GetComponent(NavPoint) as NavPoint).previousNode != null)
 {
     shortestPath.Add(curNode);
     curNode = (curNode.GetComponent(NavPoint) as NavPoint).previousNode;        
 }

 shortestPath.Add(source);
 shortestPath.Reverse();

 var testPath = shortestPath.ToBuiltin(GameObject);

 return testPath;

}

function Update() { myPath = DijkstraPath(mySource,myTarget,myWaypoints);

}

If you press Play in the Unity Editor, the empty with the DijkstraPath script should build the path in the Inspector correctly. But trying to build the XCode project fails with the SIGBUS error.

Any ideas?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Mark Grob · Aug 24, 2010 at 06:39 PM

You are referencing a null value outcome in your code. Sounds like you are coding on unity iphone.

try putting in a if != null condition or have it generate a debug log of the specific null reference it is generating.

eg.

Blockquote

function Start()

{

myWaypoints = GameObject.FindGameObjectsWithTag(tagName);

}

Blockquote

to ...

myWaypoints = GameObject.FindGameObjectsWithTag(tagName);

if (myWayPoints !=null )

{
 ***something I want to happen***
}

else {

print("Null value on myWaypoints, did I forget a Tag");
Destroy(this);

} ...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

AI Programing Resources 9 Answers

Raycast pathfinder nodes 1 Answer

Another Pathfinding/Waypoint problem 0 Answers

Physics based click to move 1 Answer

dynamic node driven room based AI 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges