使用GLS开发时报出“Must use a native order direct Buffer” 的bug,记录下解决过程,供以后回顾。
首先源码
public static IntBuffer makeIntBuffer(int[] arr) {
ByteBuffer bb = ByteBuffer.allocate(arr.length * 4);
bb.order(ByteOrder.nativeOrder());
IntBuffer ib = bb.asIntBuffer();
ib.put(arr);
ib.position(0);
return ib;
}
修改之后的代码:
public static IntBuffer makeIntBuffer(int[] arr) {
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
bb.order(ByteOrder.nativeOrder());
IntBuffer ib = bb.asIntBuffer();
ib.put(arr);
ib.position(0);
return ib;
}
原来是使用ByteBuffer.allocateDirect() 过程中,误将allocateDirect()写成了 allocate()了。