Trying to write a TriMesh to BinaryOutputCapsule causes exception on load

I'm writing a TriMesh to a BinaryOutputCapsule (as part of generating a .jme file of an imported scene).

Unfortunately, when I read back this TriMesh, I get an exception when trying to draw the trimesh, because it is trying to set the number of floats in the texture coordinate array to more than there is.

I'm pretty sure that I generate correct position, normal and texture coordinate arrays, and that the "limit" of each array is consistent with the number of vertices (position = 3nVert, normal = 3nVert, texcoord = 2*nVert).

I think I tracked it down to this following code in BinaryOutputCapsule:


    protected void write(FloatBuffer value) throws IOException {
        if (value == null) {
            write(NULL_OBJECT);
            return;
        }
        value.clear();
        int length = value.capacity();
        write(length);
        for (int x = 0; x < length; x++) {
            write(value.get());
        }
        value.rewind();
    }



This looks wrong to me. First of all, it writes all the floats in the underlying array, even if the array is created using wrap() on a float array that is shorter (and thus limit < capacity). Second, it actually modifies the object that is being written, which I would think is, in general, a no-no.

So, before I go ahead and fix this problem (which is the same in all the nio write functions), is there some reason for this? Is there something else that will stop working if I fix it?

Btw, here is my proposed fix:

    protected void write(FloatBuffer value) throws IOException {
        if (value == null) {
            write(NULL_OBJECT);
            return;
        }
        value.rewind();
        int length = value.limit();
        write(length);
        for (int x = 0; x < length; x++) {
            write(value.get());
        }
        value.rewind();
    }


Btw: applying this fix locally does fix the exception on import.

According to Issue 270 this was fixed in cvs.

Yes; I had submitted a patch and it's now applied.