Skip to content

scenegraph.io Problem with OrderedGroup #3

@psymagic

Description

@psymagic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions