As you say, the most likely explanation is that I have a bad pointer being used somewhere. The thing is I have gone over this code a bunch of times and tried lots of different checks and I just can't find what's wrong. Do you have any pointers on ways to debug the crash in the GL library?
I forgot to mention: I bind the array buffer to 0 after the call to glDrawElements(), so any future draw calls that are not using VBOs will not break. Also, I am not using VBOs for all draw calls. You keep a different VBO for each channel; is using a single VBO for several channels not allowed? If its possible to use a single buffer that would reduce the needed calls to glBindBuffer() and allowed interleaved data which would improve cache locality. Curious; did using GL_FIXED give a large performance gain? Thanks for your help. /Viktor On 16 Feb, 21:25, Robert Green <[email protected]> wrote: > You're probably pointing something to some bad memory location > somewhere. I know you didn't post all of your real code so I can't > really say for sure but it looks to me like you may be doing something > wrong with your buffers. Here's how I do it: > > -- Load -- > GL11 gl11 = (GL11) gl; > if (modelData.normals != null) { > int[] vboIds = new int[5]; > gl11.glGenBuffers(5, vboIds, 0); > vertexVBOId = vboIds[0]; > texVBOId = vboIds[1]; > normalVBOId = vboIds[2]; > indexVBOId = vboIds[3]; > lightmapVBOId = vboIds[4]; > } else { > int[] vboIds = new int[4]; > gl11.glGenBuffers(4, vboIds, 0); > vertexVBOId = vboIds[0]; > texVBOId = vboIds[1]; > indexVBOId = vboIds[2]; > lightmapVBOId = vboIds[3]; > } > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexVBOId); > gl11.glBufferData(GL11.GL_ARRAY_BUFFER, > modelData.vertices.length * > 4, BufferUtil.createDirectIntBuffer(modelData.vertices), > GL11.GL_STATIC_DRAW); > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, texVBOId); > gl11.glBufferData(GL11.GL_ARRAY_BUFFER, > modelData.tex.length * 4, > BufferUtil.createDirectIntBuffer(modelData.tex), GL11.GL_STATIC_DRAW); > if (modelData.normals != null) { > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, > normalVBOId); > gl11.glBufferData(GL11.GL_ARRAY_BUFFER, > modelData.normals.length * > 4, BufferUtil.createDirectIntBuffer(modelData.normals), > GL11.GL_STATIC_DRAW); > } > gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, > indexVBOId); > gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, > modelData.indices.length * 2, > BufferUtil.createDirectShortBuffer(modelData.indices), > GL11.GL_STATIC_DRAW); > if (hasLightMap) { > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, > lightmapVBOId); > gl11.glBufferData(GL11.GL_ARRAY_BUFFER, > lightMapModelData.tex.length * 4, > BufferUtil.createDirectIntBuffer(lightMapModelData.tex), > GL11.GL_STATIC_DRAW); > } > BaseRenderer.checkErrors(gl11); > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0); > gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0); > > -- Draw -- > > // use VBOs > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexVBOId); > gl11.glVertexPointer(3, GL10.GL_FIXED, 0, 0); > if (modelData.normals != null) { > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, > normalVBOId); > gl11.glNormalPointer(GL10.GL_FIXED, 0, 0); > } > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, > texVBOId); > gl11.glTexCoordPointer(2, GL10.GL_FIXED, 0, > 0); > //gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, > indexVBOId); > // the main draw call > gl11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount); > //gl11.glDrawElements(GL10.GL_TRIANGLES, vertexCount, > GL10.GL_UNSIGNED_SHORT, 0); > // clean up > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0); > //gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0); > > This code draws without indices but the commented code for indices is > there. > I use fixed point coordinates for verts, normals and UVs. You'd want > to change that to floats for what you're doing. > > On Feb 16, 1:42 pm, Viktor Linder <[email protected]> wrote: > > > I am having trouble with implementing VBOs for my game. > > I get crashes at random when calling glDrawElements() directly after > > glGenBuffers() / glBufferData(). > > The crashes disappear when I add printouts which leads me to believe > > it might be a race condition between glBufferData() and > > glDrawElements() of some sort. > > Or I am doing something else that breaks it, but I can't see what. > > > Here's what I do: > > > ... > > gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); > > gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); > > ... > > if(geometry not in cache) { > > gl11.glGenBuffers(1, _temp_handle, 0); > > _geo_id = _temp_handle[0]; > > > // produce text geometry to scratch buffer (allocated with > > ByteBuffer.allocateDirect()) > > int off = DynamicBuffer.allocate(_buf_size_floats); > > TextProducer.create_geometry(_font, _text, DynamicBuffer._buffer, > > off); > > > // upload geometry > > gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, _geo_id); > > > DynamicBuffer._buffer.position(off); > > gl11.glBufferData(GL11.GL_ARRAY_BUFFER, _buf_size_bytes, > > DynamicBuffer._buffer, GL11.GL_STATIC_DRAW); > > > DynamicBuffer.deallocate_last(_buf_size_floats); > > > // set vertex pointer > > gl11.glVertexPointer(3, GL10.GL_FLOAT, 0, 0); > > gl11.glTexCoordPointer(2, GL10.GL_FLOAT, 0, _pos_size_bytes); > > > insert_in_cache();} else { > > > ... bind + set vertex pointer using existing VBO ... > > > } > > > ... > > gl.glDrawElements(); // <--- sometimes this call crashes, always after > > buffer was just allocated/produced (ie the geometry-not-in-cache code > > path) > > ... > > > gl.glDisableClientState(VERTEX...); > > gl.glDisableClientState(TEXCOORD...); > > > Sometimes the call to glDrawElements() crashes. The crash only happens > > when glDrawElements() is called right after the buffer has been > > allocated and written (ie "geometry not in cache" is true). > > The crash seems more common if the produced buffer is a few kb or more > > in size. > > If I insert a Log.d() call in between glVertexPointer3f() and > > glDrawElements() the crash goes away. > > > I have double checked that the GL calls are not setting the error > > flag, and I am not writing past any buffer limit or feeding incorrect > > sizes etc to glBufferData(). Note that everything renders correctly > > without artifacts up to the crash. The crash does not happen for the > > same geometry all the time, a piece of geometry can be produced and > > rendered correctly, then be re-produced and crash. > > > Before I make a minimal reproducible example, I thought I would ask > > this group if anyone else > > have experienced the same trouble when using a VBO right after call to > > glBufferData()? > > > All answers appreciated! > > /Viktor > > > PS. > > This is the crash dump: > > 02-16 20:23:00.979: INFO/DEBUG(14143): *** *** *** *** *** *** *** *** > > *** *** *** *** *** *** *** *** > > 02-16 20:23:00.979: INFO/DEBUG(14143): Build fingerprint: 'android- > > devphone1/dream_devphone/dream/trout:1.6/DRC83/14721:user/gfh,test- > > keys' > > 02-16 20:23:00.979: INFO/DEBUG(14143): pid: 17564, tid: 17580 >>> > > com.mygame.mygame <<< > > 02-16 20:23:00.979: INFO/DEBUG(14143): signal 11 (SIGSEGV), fault addr > > 002df000 > > 02-16 20:23:00.979: INFO/DEBUG(14143): r0 001b9c28 r1 002deff0 r2 > > 00000003 r3 001be178 > > 02-16 20:23:00.979: INFO/DEBUG(14143): r4 002deff4 r5 001be17c r6 > > 00000044 r7 000003ff > > 02-16 20:23:00.979: INFO/DEBUG(14143): r8 00000000 r9 001be170 10 > > 00000003 fp 001b9c14 > > 02-16 20:23:00.979: INFO/DEBUG(14143): ip 00000002 sp 44944d00 lr > > 8042b8dc pc 8043fdf8 cpsr 20000010 > > 02-16 20:23:02.669: INFO/DEBUG(14143): #00 pc 0003fdf8 / > > system/lib/libhgl.so > > 02-16 20:23:02.669: INFO/DEBUG(14143): #01 lr 8042b8dc / > > system/lib/libhgl.so > > 02-16 20:23:02.669: INFO/DEBUG(14143): stack: > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cc0 0000000c > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cc4 001b53d4 [heap] > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cc8 001b39b0 [heap] > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944ccc 001b49b0 [heap] > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cd0 00000000 > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cd4 00000000 > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cd8 001b3db0 [heap] > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944cdc 8043c1c0 /system/ > > lib/libhgl.so > > 02-16 20:23:02.679: INFO/DEBUG(14143): 44944ce0 001c3e78 [heap] > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944ce4 009c8330 > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944ce8 001b9c08 [heap] > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944cec 001b39b0 [heap] > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944cf0 001b44ac [heap] > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944cf4 00000005 > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944cf8 df002777 > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944cfc e3a070ad > > 02-16 20:23:02.689: INFO/DEBUG(14143): #00 44944d00 00000400 > > 02-16 20:23:02.689: INFO/DEBUG(14143): 44944d04 001c3e78 [heap] > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d08 009cd330 > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d0c 001b9c08 [heap] > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d10 001b39b0 [heap] > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d14 001b44ac [heap] > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d18 00000000 > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d1c 00000800 > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d20 00000008 > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d24 00000000 > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d28 00000ec4 > > 02-16 20:23:02.699: INFO/DEBUG(14143): 44944d2c 002c3dd0 [heap] > > 02-16 20:23:02.709: INFO/DEBUG(14143): 44944d30 001b39b0 [heap] > > 02-16 20:23:02.709: INFO/DEBUG(14143): 44944d34 001b49b0 [heap] > > 02-16 20:23:02.709: INFO/DEBUG(14143): 44944d38 001b3db0 [heap] > > 02-16 20:23:02.709: INFO/DEBUG(14143): 44944d3c 001c3e78 [heap] > > 02-16 20:23:02.709: INFO/DEBUG(14143): 44944d40 00000001 > > 02-16 20:23:02.709: INFO/DEBUG(14143): 44944d44 8041fc14 /system/ > > lib/libhgl.so -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

