Strange issue with recursion?

So essentially, the following snippet of code loops endlessly.

		while (parent != null) {
			System.out.println(parent);
			offset.add(offsetFromParentWithRotation());
			parent = parent.getParent();
		}

Why is that? Am I not allowed to set the parent like that, or am I missing something very obvious?

Is [icode]getParent[/icode] meant to return null? Your code does not make sense. Why are you checking whether parent is not null? Why are you using a loop? What’s the point of parent.getParent()?

P.S: Iteration != recursion. Iteration is using a loop to check a condition. Recursion is the calling of a method inside that same method.

Iteration:


while(x < 10) {
    x++;
}

Recursion:


int doSomethingWithX(int x) {
    if(x < 10)
        doSomethingWithX(x++);
    return x;
}

Somewhere in your code you must be “recursively” set parent of a parent with itself.

Are you developing some kind of Bone animation code?

Its possible that you have a loop in your bones.
So that would mean that at some point the parent of one of your bones is the same bone as the bone you began with :slight_smile: