gpt4 book ai didi

android - glDrawElements 在设备上崩溃,在模拟器上运行良好

转载 作者:搜寻专家 更新时间:2023-11-01 08:12:24 28 4
gpt4 key购买 nike

我一直在使用 OpenGL-ES 而不是 Android。一切顺利,我正在制作 2D 游戏,我可以在屏幕上显示 Sprite ,移动它们等等。但所有这些都只能在模拟器上运行。在我的摩托罗拉 Droid 1 上,它只是关闭(即使没有强制关闭警告)。

调试器没有抛出任何东西,也没有发送调试文本,所以我在某些行停下来,逐步进入并逐步结束,直到到达应用程序突然关闭的地方。

结果是,它在这一行结束:

gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indices);

为了提供帮助,这是我的完整绘图功能:

    /**
* Draw the sprite on the screen
* @param gl OpenGLES Context
*/
public void draw(GL10 gl, Vector3 position){
if(textured)
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);

gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef(position.X, position.Y, position.Z);
gl.glScalef(scale.X, scale.Y, 1);
gl.glRotatef(rotation.X, 1.0f, 0.f, 0.0f);
gl.glRotatef(rotation.Y, 0.0f, 1.0f, 0.0f);
gl.glRotatef(rotation.Z, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);

if(textured)
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, uvs);

//gl.glColorPointer(4, GL10.GL_FLOAT, 0, colors);

gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indices);
gl.glPopMatrix();
}

我不知道是什么原因造成的,因为它运行良好,在模拟器上显示我的 Sprite 等,但在设备上关闭。

这是 logcat 日志:

12-20 01:28:29.615: D/AndroidRuntime(3103): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-20 01:28:29.615: I/AndroidRuntime(3103): Heap size: -Xmx24m
12-20 01:28:29.615: D/AndroidRuntime(3103): CheckJNI is OFF
12-20 01:28:29.615: D/dalvikvm(3103): creating instr width table
12-20 01:28:29.787: D/AndroidRuntime(3103): Calling main entry com.android.commands.pm.Pm
12-20 01:28:29.795: D/AndroidRuntime(3103): Shutting down VM
12-20 01:28:29.803: D/dalvikvm(3103): GC_CONCURRENT freed 101K, 71% free 306K/1024K, external 0K/0K, paused 1ms+0ms
12-20 01:28:29.803: I/AndroidRuntime(3103): NOTE: attach of thread 'Binder Thread #3' failed
12-20 01:28:29.803: D/jdwp(3103): Got wake-up signal, bailing out of select
12-20 01:28:29.803: D/dalvikvm(3103): Debugger has detached; object registry had 1 entries
12-20 01:28:30.194: D/AndroidRuntime(3113): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-20 01:28:30.194: I/AndroidRuntime(3113): Heap size: -Xmx24m
12-20 01:28:30.194: D/AndroidRuntime(3113): CheckJNI is OFF
12-20 01:28:30.194: D/dalvikvm(3113): creating instr width table
12-20 01:28:30.365: D/AndroidRuntime(3113): Calling main entry com.android.commands.am.Am
12-20 01:28:30.381: I/ActivityManager(2047): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.cygnus.shootaray/.ShotaRayActivity } from pid 3113
12-20 01:28:30.405: D/AndroidRuntime(3113): Shutting down VM
12-20 01:28:30.405: D/dalvikvm(3113): GC_CONCURRENT freed 103K, 69% free 324K/1024K, external 0K/0K, paused 0ms+0ms
12-20 01:28:30.405: E/dalvikvm(3121): could not disable core file generation for pid 3121: Operation not permitted
12-20 01:28:30.405: I/ActivityManager(2047): Start proc com.cygnus.shootaray for activity com.cygnus.shootaray/.ShotaRayActivity: pid=3121 uid=10066 gids={}
12-20 01:28:30.412: I/AndroidRuntime(3113): NOTE: attach of thread 'Binder Thread #3' failed
12-20 01:28:30.412: D/jdwp(3113): Got wake-up signal, bailing out of select
12-20 01:28:30.412: D/dalvikvm(3113): Debugger has detached; object registry had 1 entries
12-20 01:28:30.498: D/szipinf(3121): Initializing inflate state
12-20 01:28:30.631: D/libEGL(3121): loaded /system/lib/egl/libEGL_POWERVR_SGX530_121.so
12-20 01:28:30.631: D/libEGL(3121): loaded /system/lib/egl/libGLESv1_CM_POWERVR_SGX530_121.so
12-20 01:28:30.647: D/libEGL(3121): loaded /system/lib/egl/libGLESv2_POWERVR_SGX530_121.so
12-20 01:28:30.811: I/ActivityManager(2047): Displayed com.cygnus.shootaray/.ShotaRayActivity: +413ms
12-20 01:28:30.842: D/dalvikvm(3121): GC_EXTERNAL_ALLOC freed 58K, 50% free 2702K/5379K, external 0K/0K, paused 54ms
12-20 01:28:30.952: I/DEBUG(1456): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-20 01:28:30.959: I/DEBUG(1456): Build fingerprint: 'MOTO_RTEU/umts_sholes/umts_sholes/sholes:2.2.1/SHOLS_U2_05.26.3/296482885:user/release-keys'
12-20 01:28:30.959: I/DEBUG(1456): pid: 3121, tid: 3130 >>> com.cygnus.shootaray <<<
12-20 01:28:30.959: I/DEBUG(1456): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
12-20 01:28:30.959: I/DEBUG(1456): r0 44d2e0c0 r1 00000000 r2 00000000 r3 00000000
12-20 01:28:30.959: I/DEBUG(1456): r4 00154e20 r5 00155c80 r6 00000001 r7 00000004
12-20 01:28:30.959: I/DEBUG(1456): r8 00000024 r9 00000000 10 00000004 fp 00000000
12-20 01:28:30.959: I/DEBUG(1456): ip 8096a63c sp 442eba90 lr 80906a44 pc afd0d078 cpsr 60000010
12-20 01:28:30.959: I/DEBUG(1456): d0 6472656767756265 d1 0000000043000000
12-20 01:28:30.959: I/DEBUG(1456): d2 0000000000000000 d3 4300000000000000
12-20 01:28:30.959: I/DEBUG(1456): d4 0000000000000000 d5 0000000000000000
12-20 01:28:30.959: I/DEBUG(1456): d6 0000000000166b40 d7 0000000000000000
12-20 01:28:30.959: I/DEBUG(1456): d8 0000000000204762 d9 0000000000000000
12-20 01:28:30.959: I/DEBUG(1456): d10 0000000000000000 d11 0000000000000000
12-20 01:28:30.959: I/DEBUG(1456): d12 0000000000000000 d13 0000000000000000
12-20 01:28:30.959: I/DEBUG(1456): d14 0000000000000000 d15 0000000000000000
12-20 01:28:30.967: I/DEBUG(1456): d16 41df86f6ff34fdf4 d17 3f50624dd2f1a9fc
12-20 01:28:30.967: I/DEBUG(1456): d18 41c6803ace000000 d19 00000000000000ff
12-20 01:28:30.967: I/DEBUG(1456): d20 000000000000ff00 d21 0000010000000000
12-20 01:28:30.967: I/DEBUG(1456): d22 000000000000d516 d23 00000001000002fd
12-20 01:28:30.967: I/DEBUG(1456): d24 0000000000002645 d25 0000000000000000
12-20 01:28:30.967: I/DEBUG(1456): d26 0000000000002645 d27 0000000000000000
12-20 01:28:30.967: I/DEBUG(1456): d28 0000000000002645 d29 0000000000000000
12-20 01:28:30.967: I/DEBUG(1456): d30 0000000000000000 d31 0000000000000000
12-20 01:28:30.967: I/DEBUG(1456): scr 20000010
12-20 01:28:31.100: I/DEBUG(1456): #00 pc 0000d078 /system/lib/libc.so
12-20 01:28:31.100: I/DEBUG(1456): #01 lr 80906a44 /system/lib/egl/libGLESv1_CM_POWERVR_SGX530_121.so
12-20 01:28:31.100: I/DEBUG(1456): code around pc:
12-20 01:28:31.100: I/DEBUG(1456): afd0d058 f400071d f5d1f000 f5d1f040 e2522040
12-20 01:28:31.100: I/DEBUG(1456): afd0d068 3a000009 f5d1f080 f5d1f0c0 f5d1f100
12-20 01:28:31.100: I/DEBUG(1456): afd0d078 f421020d f421420d f5d1f100 e2522040
12-20 01:28:31.100: I/DEBUG(1456): afd0d088 f400022d f400422d 2afffff8 e2822040
12-20 01:28:31.100: I/DEBUG(1456): afd0d098 e2522020 3a000003 f421020d e2522020
12-20 01:28:31.100: I/DEBUG(1456): code around lr:
12-20 01:28:31.100: I/DEBUG(1456): 80906a24 e3530000 1a000005 e1a03007 e59c0028
12-20 01:28:31.100: I/DEBUG(1456): 80906a34 e59c102c e59c2024 e1a0e00f e59cf034
12-20 01:28:31.100: I/DEBUG(1456): 80906a44 e2866001 e2855004 e5942eb0 e3a03001
12-20 01:28:31.100: I/DEBUG(1456): 80906a54 e1560002 3affffec e2840d77 e1a01008
12-20 01:28:31.100: I/DEBUG(1456): 80906a64 e2800004 e1a02003 e8bd41f0 ea00cdd5
12-20 01:28:31.100: I/DEBUG(1456): stack:
12-20 01:28:31.100: I/DEBUG(1456): 442eba50 00000000
12-20 01:28:31.100: I/DEBUG(1456): 442eba54 00000000
12-20 01:28:31.100: I/DEBUG(1456): 442eba58 00000000
12-20 01:28:31.100: I/DEBUG(1456): 442eba5c 00000000
12-20 01:28:31.100: I/DEBUG(1456): 442eba60 00000000
12-20 01:28:31.108: I/DEBUG(1456): 442eba64 00000000
12-20 01:28:31.108: I/DEBUG(1456): 442eba68 00000001
12-20 01:28:31.108: I/DEBUG(1456): 442eba6c 00000000
12-20 01:28:31.108: I/DEBUG(1456): 442eba70 00000000
12-20 01:28:31.108: I/DEBUG(1456): 442eba74 00154e20
12-20 01:28:31.108: I/DEBUG(1456): 442eba78 00155c7c
12-20 01:28:31.108: I/DEBUG(1456): 442eba7c 00000000
12-20 01:28:31.108: I/DEBUG(1456): 442eba80 00000004
12-20 01:28:31.108: I/DEBUG(1456): 442eba84 00000024
12-20 01:28:31.108: I/DEBUG(1456): 442eba88 df002777
12-20 01:28:31.108: I/DEBUG(1456): 442eba8c e3a070ad
12-20 01:28:31.108: I/DEBUG(1456): #00 442eba90 44d2e0c0
12-20 01:28:31.108: I/DEBUG(1456): 442eba94 80906a44 /system/lib/egl/libGLESv1_CM_POWERVR_SGX530_121.so
12-20 01:28:31.108: I/DEBUG(1456): 442eba98 00154e20
12-20 01:28:31.108: I/DEBUG(1456): 442eba9c 00000004
12-20 01:28:31.108: I/DEBUG(1456): 442ebaa0 000a49c8
12-20 01:28:31.108: I/DEBUG(1456): 442ebaa4 00000006
12-20 01:28:31.108: I/DEBUG(1456): 442ebaa8 8096a5e4
12-20 01:28:31.108: I/DEBUG(1456): 442ebaac 8090813c /system/lib/egl/libGLESv1_CM_POWERVR_SGX530_121.so
12-20 01:28:31.108: I/DEBUG(1456): 442ebab0 000a3248
12-20 01:28:31.108: I/DEBUG(1456): 442ebab4 00163500
12-20 01:28:31.108: I/DEBUG(1456): 442ebab8 00000000
12-20 01:28:31.108: I/DEBUG(1456): 442ebabc 00000006
12-20 01:28:31.108: I/DEBUG(1456): 442ebac0 44f5c420
12-20 01:28:31.108: I/DEBUG(1456): 442ebac4 00154e20
12-20 01:28:31.108: I/DEBUG(1456): 442ebac8 00000004
12-20 01:28:31.108: I/DEBUG(1456): 442ebacc 8096a5e4
12-20 01:28:31.108: I/DEBUG(1456): 442ebad0 00000006
12-20 01:28:31.108: I/DEBUG(1456): 442ebad4 00000004
12-20 01:28:32.162: I/BootReceiver(2047): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
12-20 01:28:32.178: E/InputDispatcher(2047): channel '407c49d0 com.cygnus.shootaray/com.cygnus.shootaray.ShotaRayActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
12-20 01:28:32.178: E/InputDispatcher(2047): channel '407c49d0 com.cygnus.shootaray/com.cygnus.shootaray.ShotaRayActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
12-20 01:28:32.186: D/Zygote(1469): Process 3121 terminated by signal (11)
12-20 01:28:32.225: D/dalvikvm(2047): GC_FOR_MALLOC freed 390K, 43% free 5438K/9415K, external 1601K/4601K, paused 59ms
12-20 01:28:32.225: I/WindowManager(2047): WIN DEATH: Window{407c49d0 com.cygnus.shootaray/com.cygnus.shootaray.ShotaRayActivity paused=false}
12-20 01:28:32.225: I/ActivityManager(2047): Process com.cygnus.shootaray (pid 3121) has died.
12-20 01:28:32.241: I/WindowManager(2047): WIN DEATH: Window{407dd460 SurfaceView paused=false}
12-20 01:28:32.303: D/dalvikvm(2047): GC_FOR_MALLOC freed 317K, 42% free 5505K/9415K, external 1601K/4601K, paused 43ms
12-20 01:28:32.342: W/InputManagerService(2047): Got RemoteException sending setActive(false) notification to pid 3121 uid 10066

有什么提示吗?

编辑:

正如 Spoon Thumb 所提到的,这是我的启用/禁用调用:

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

for (Drawable i : toDraw) {
i.draw(gl);
}

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

这些在 onDrawFrame 上。它调用 drawable.draw,这是我发布的第一个函数。

如果有帮助,这是我启用和禁用的 onSurfaceChanged:

public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0.0f, width, 0.0f, height, 0.0f, 1.0f);

gl.glShadeModel(GL10.GL_FLAT);
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}

此外,我对代码进行了一些编辑,不确定是否进行了更改,但现在我没有收到 SIGSEGV 11,代码在我的设备上运行,但我什么也看不到。

最佳答案

我设法自己完成了这项工作。

我不完全知道我做了什么,但它在以下情况下停止崩溃:

  • 将 glDrawElements 更改为 glDrawArray

好吧,为了做到这一点,我必须改变我构建四边形的所有方式,现在,我不再使用索引(尽管我应该使用)。

更改:

gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indices);

到:

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

不要忘记指向顶点数组。

  • 为每次绘制启用和禁用Clientstates,而不是每帧一次。

代替:

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

drawspriteone();
drawspritetwo();
drawspriteN();...

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

我必须在绘制函数的内部执行此操作,如下所示:

gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.id);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, uvs);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  • 啊,也尝试在每个绘图中启用和禁用纹理。


我不知道这些更改中的哪些更改使该应用程序可以在我的手机上运行,​​但即使它现在正在运行,它仍然不会绘制任何东西。是的,我可以看到缓冲区清晰的颜色,但没有纹理。

我做了什么?

好吧,这是大量的试验和错误,一些研究让我认为 Milestones 的 GPU(它是 Moto Droid 的欧洲/南美版本)和其他一些设备的 OpenGL 驱动程序的工作方式完全不同,而且他们不支持更改颜色格式。也许这可能是真的,但事实并非如此。

我更改了调用顺序、设置状态等。但我的错误是如此、如此、如此愚蠢,以至于我今天才找到它。

让我们切入答案:

在 0.0f Z 坐标上绘制二维四边形!

为什么?我不知道。但是,我的每个 Sprite 的 Z 坐标都设置为 0.1f,我更改了它们,现在我可以看到所有 Sprite 了。奇怪吧?更奇怪的是:模拟器可以看到 z 设置为 0.1f 的纹理,但设备没有..

只是想让你知道,这是我的视口(viewport)设置:

gl.glOrthof(0.0f, width, 0.0f, height, 0.0f, 1.0f);

nearplane0.0ffarplane1.0f。它不应该接受 0.0f 和 1.0f 之间的值吗?

谢谢!这是我问题的最终答案(:

关于android - glDrawElements 在设备上崩溃,在模拟器上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8570465/

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