SkeletonControl.getAttachmentsNode() crash

Hi.



I’ve been replacing the deprecated AnimControl.getAttachmentsNode() in my project, and got a crash.



The two methods look slightly different:



AnimControl:

[java]…

Node n = b.getAttachmentsNode();

if (spatial != null) {

Node model = (Node) spatial;

model.attachChild(n);

}

…[/java]



SkeletonControl:

[java]…

Node n = b.getAttachmentsNode();

Node model = (Node) spatial;

model.attachChild(n);

…[/java]



My “model / spatial” was null, and thus it crashed when trying to attach “n”.



I replaced those couple of lines with the ones from AnimControl and it worked fine:

New SkeletonControl:

[java]

public Node getAttachmentsNode(String boneName) {

Bone b = skeleton.getBone(boneName);

if (b == null) {

throw new IllegalArgumentException("Given bone name does not exist "

  • “in the skeleton.”);

    }



    Node n = b.getAttachmentsNode();

    if (spatial != null) {

    Node model = (Node) spatial;

    model.attachChild(n);

    }

    return n;

    }[/java]



    Don’t know if something’s wrong with my skeleton, but less crashes is good, right?
2 Likes

mhhh right but the thing is, I added the null check on the spatial in AnimControl when I deprecated the method, because with the changes I made there was a chance the spatial be null at this point.

So basically the method in SkeletonControl now is the one of the old AnimControl. The spatial should not be null…

Maybe that was an unreported bug on the old animControl.

Anyway i’ll fix this tonight, thanks ;).

1 Like

ok I looked into this, and the spatial should really not be null.



The problem was in the cloneForSpatial, where I did not set the spatial to the clonedControl before calling getAttachmentsNode.



Could you please test with the last revision?