当我使用GLES 3.0 VBO在Android上编程项目时,有时应用程序在调用方法GLES30.glBufferData时崩溃。如果我使用简单数据,当我从文件中获取数据时崩溃,就不会发生崩溃。
int[] vboIDs = new int[1];
GLES30.glGenBuffers(1, vboIDs, 0);
GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, vboIDs[0]);
GLES30.glBufferData(GLES30.GL_ELEMENT_ARRAY_BUFFER, size, buffer, GLES30.GL_STATIC_DRAW);//size=1296 buffer.capacity()=1296
GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0);
它刚刚崩溃,没有异常日志。 缓冲区的格式是错误的吗?下面是我如何获得 buffer 实例,参数byteBuffer是从二进制文件中获取的,
public static ByteBuffer createSlice(
ByteBuffer byteBuffer, int position, int length)
{
if (byteBuffer == null)
{
return null;
}
int oldPosition = byteBuffer.position();
int oldLimit = byteBuffer.limit();
try
{
int newLimit = position + length;
if (newLimit > byteBuffer.capacity())
{
throw new IllegalArgumentException(
"The new limit is " + newLimit + ", but the capacity is "
+ byteBuffer.capacity());
}
byteBuffer.limit(newLimit);
byteBuffer.position(position);
ByteBuffer slice = byteBuffer.slice();
slice.order(byteBuffer.order());
return slice;
}
finally
{
byteBuffer.limit(oldLimit);
byteBuffer.position(oldPosition);
}
}
答案 0 :(得分:0)
缓冲区数据崩溃通常意味着您已经离开缓冲区的末尾并访问了未映射的页面,因此请检查size
对于您正在上传的buffer
是否正确。