开发者

Exception instantiating FloatBuffer[]

开发者 https://www.devze.com 2023-04-13 09:28 出处:网络
I\'m trying to create an array of 144 FloatBuffers so I can easily access each one using an integer to pick which one. No, I don\'t mean a FloatBuffer 144 long. I\'m investigating using 开发者_开发问答

I'm trying to create an array of 144 FloatBuffers so I can easily access each one using an integer to pick which one. No, I don't mean a FloatBuffer 144 long. I'm investigating using 开发者_开发问答a class to contain all the FloatBuffers, but it'll take some time. Any thoughts?

I get

java.lang.ArrayIndexOutOfBoundsException: 0

on this line, no matter what method I use to try to instantiate the new FloatBuffer INTO the array:

    for(int i=0; i<144;i++){
    vbuffers[i] = BufferUtils.createFloatBuffer(buffervolume*7);
    }

I also tried this and got the same error:

        vbuffers[i]=FloatBuffer.allocate(buffervolume*7);

Here is the full relevant code:

public class myclass {

public FloatBuffer[] vbuffers;

public myclass(){
    vbuffers=new FloatBuffer[chunklimit*chunklimit*4];
    for(int i=0; i<144;i++){
    vbuffers[i] = BufferUtils.createFloatBuffer(chunkvolume*7);
    }
}
}

I would like to add that I ended up using one large FloatBuffer and glbuffersubdata to manage my data and got really great results.


The exception strongly suggests that vbuffers is a zero-length array. Check that chunklimit is non-zero.

In general, when you have code like this:

vbuffers = new FloatBuffer[chunklimit*chunklimit*4];
for(int i = 0; i < 144; i++) {
    vbuffers[i] = ...

there's a risk that chunklimit*chunklimit*4 won't be the same as 144, resulting in errors.

It is usually a better idea to use the size of the array in the for loop:

vbuffers = new FloatBuffer[chunklimit*chunklimit*4];
for(int i = 0; i < vbuffers.length; i++) {
    vbuffers[i] = ...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号