x


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?

more ▼

asked May 17 '10 at 05:25 AM

Zootie gravatar image

Zootie
76 5 6 11

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);

} ...

more ▼

answered Aug 24 '10 at 06:39 PM

Mark Grob gravatar image

Mark Grob
12 1 1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x252

asked: May 17 '10 at 05:25 AM

Seen: 1043 times

Last Updated: May 17 '10 at 05:25 AM