locked
OpenGL ES 2.0: ElementArrayBuffer+DrawElements = SIGSEGV crash RRS feed

  • Question

  • User77086 posted

    Hello, need some help with OpenGL ES 2.0 on Android. i altered GLTriangle20-1.0 example to draw a triangle using VBO. If i put vertices in the buffer and draw with DrawElements referring to index array everything is working fine. If however i put both vertices and indices in the buffer i get SIGSEGV crash when calling DrawElements. Same GL code work in IOS in both cases. Here's the drawing code (problem section commented):

            float[] vertices = { -0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, 0.5f, 0.0f };
            ushort[] indices = { 0, 1, 2 };
    
            GL.ClearColor(1f, 1f, 1f, 1.0f);
            GL.Clear (ClearBufferMask.ColorBufferBit);
    
            int VertexVBO=0; 
            GL.GenBuffers(1, out VertexVBO);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexVBO);
            unsafe
            {
                fixed (float* ptr = vertices)
                {
                    GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * vertices.Length), new IntPtr(ptr), BufferUsage.StaticDraw);
                }
            }
            GL.VertexAttribPointer(mPositionHandle, 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0);
    
            //Drawing triangle using indices without putting them into buffer works fine.
            unsafe
            {
                fixed (ushort* ptr = indices)
                {
                    GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, new IntPtr(ptr));
                }
    
            }
    
    
            // Drawing triangle using indices stored in buffer leads to a SIGSEGV crash. Same code on IOS works fine.
            /* 
            int IndexVBO = 0;
            GL.GenBuffers(1, out IndexVBO);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexVBO);
            unsafe
            {
                fixed (ushort* ptr = indices)
                {
                    GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(sizeof(ushort) * indices.Length), new IntPtr(ptr), BufferUsage.StaticDraw);
                }
            }
            GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, 0);*/
    

    I tried on Genymotion API 17-20 - same behavior on all of them. Should i do this some other way on android?

    Friday, May 22, 2015 1:18 PM

All replies

  • User79922 posted

    I can confirm I am having the same issue, at least I can continue debugging on Android now by not using IBO as a work around. Can anyone confirm this as a possible bug?

    Wednesday, June 3, 2015 5:19 AM
  • User147071 posted

    Any solution to this?

    Sunday, July 3, 2016 4:41 AM
  • User295151 posted

    After about 2 days of beating my head against a wall, I solved this by changing the last parameter of the DrawElements call - GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, IntPtr.Zero);

    Friday, January 27, 2017 9:40 PM