java3d-utils icon indicating copy to clipboard operation
java3d-utils copied to clipboard

scenegraph.io Problem with OrderedGroup

Open psymagic opened this issue 10 years ago • 0 comments

When writing an OrderedGroup that has its index array set to null, j3d throws: java.lang.NullPointerException at com.sun.j3d.utils.scenegraph.io.state.javax.media.j3d.OrderedGroupState.writeObject(OrderedGroupState.java:63)

Not sure if this is a bug, as one can always set the array, but considering Null is a legit value regarding the official OrderedGroupState docs, it would be nice if OrderedGroupState could handle an empty index array.

psymagic commented 21 hours ago After investigating a little further, it really seems like someone forgot to implement io for the case of OrderedGroup.getChildIndexOrder() == null.

Just did a working fix with these lines in com.sun.j3d.utils.scenegraph.io.state.javax.media.j3d.OrderedGroupState:

@Override public void writeObject(DataOutput out) throws IOException { super.writeObject(out);

int[] childIndexOrder = ((OrderedGroup) node).getChildIndexOrder();

if (childIndexOrder == null) {
    out.writeInt(0);
} else {
    out.writeInt(childIndexOrder.length);
    for (int i = 0; i < childIndexOrder.length; i++) {
        out.writeInt(childIndexOrder[i]);
    }
}

}

@Override public void readObject(DataInput in) throws IOException { super.readObject(in);

int length = in.readInt();
int[] childIndexOrder;

if (length == 0) {
    childIndexOrder = null;
} else {
    childIndexOrder = new int[length];
    for (int i = 0; i < childIndexOrder.length; i++) {
        childIndexOrder[i] = in.readInt();
    }
}
((OrderedGroup) node).setChildIndexOrder(childIndexOrder);

} It might not be perfect thou.

psymagic avatar Jan 11 '16 17:01 psymagic