gpt4 book ai didi

Android - 为什么我收到致命信号?

转载 作者:太空狗 更新时间:2023-10-29 14:27:54 27 4
gpt4 key购买 nike

我正在尝试使用 opengl es 在屏幕上显示一些点。这是ondraw的代码:

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColor4f(0, 255, 0, 0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, buffer);
gl.glDrawArrays(GL10.GL_POINTS, 0, points.length);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

谁能告诉我我做错了什么???

编辑:生成缓冲区和点的代码

    points = new float[12288];
int pos = 0;
for (float y = 0; y < 64; y++) {
for (float x = 0; x < 64; x++) {
points[pos++] = x/100;
points[pos++] = y/100;
points[pos++] = 0;
}
}

ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(points.length * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
// allocates the memory from the byte buffer
buffer = vertexByteBuffer.asFloatBuffer();
// fill the vertexBuffer with the vertices
buffer.put(points);
// set the cursor position to the beginning of the buffer
buffer.position(0);

和 logcat 的错误:

04-17 06:38:11.296:A/libc(24276):0x41719000 处的致命信号 11 (SIGSEGV)(代码=2)

这个错误发生在 gl.glDrawArrays

最佳答案

我认为这是问题所在:

gl.glDrawArrays(GL10.GL_POINTS, 0, points.length);

glDrawArrays 获取您要绘制的顶点 的数量。您给它的 floats 数量太大了 3 倍。因此,opengl 实际上是在尝试从您的点数组中读取 12288 vertices = 36,xxx floats,这超出了数组的范围。

关于Android - 为什么我收到致命信号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10183861/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com