monamona
monamona

Reputation: 1246

IllegalArgumentException: The new limit is 5, but the capacity is 0 on buffer view data access in jgltf

I originally wanted to just convert my DefaultGltfModel into a Json string, but ran into some unforseen issues. I traced the exception I got down to some place in the library, and eventually created this MRE.

Using Jglf Version 2.0.4 from Maven Central:

  @Test
  public void testBufferViewSlice() {
    ByteBuffer byteBuffer = Buffers.create(10);
    for (byte i = 0; i < 10; i++)
    {
      byteBuffer.put(i);
    }

    DefaultBufferModel bufferModel = new DefaultBufferModel();
    bufferModel.setBufferData(byteBuffer);

    DefaultBufferViewModel defaultBufferViewModel = new DefaultBufferViewModel(GltfConstants.GL_ARRAY_BUFFER);
    defaultBufferViewModel.setBufferModel(bufferModel);
    defaultBufferViewModel.setByteOffset(0);
    defaultBufferViewModel.setByteLength(5);

    ByteBuffer slice = defaultBufferViewModel.getBufferViewData(); //Here is the exception thrown
  }

Exception:

java.lang.IllegalArgumentException: The new limit is 5, but the capacity is 0

    at de.javagl.jgltf.model.io.Buffers.createSlice(Buffers.java:109)
    at de.javagl.jgltf.model.impl.DefaultBufferViewModel.getBufferViewData(DefaultBufferViewModel.java:153)
    at xxx.gltf.AVSGLTFBuilderTests.testBufferViewSlice(AVSGLTFBuilderTests.java:167)
        ...
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

I don't quite understand what the problem is with my code. As far as I know, this should give me a slice of the buffer using the first five bytes?

Upvotes: 0

Views: 33

Answers (0)

Related Questions