glDrawElements() unexplained ERROR!

i have a runtime error in this portion of code demended to draw a curved surface … my 3d engine is totally written in java using jogl … and is capable to rendering Quake3 Level complete with lightmaps … (without curved surface right now :()
the code is:

public void draw(GL gl) {
list = gl.glGenLists(1);
gl.glNewList(list, gl.GL_COMPILE_AND_EXECUTE);
int total = meshArray.length;
int line = meshArray[0].length;

    for (int i = 0; i < total;  i++)
         gl.glDrawElements(gl.GL_TRIANGLE_STRIP, line, gl.GL_UNSIGNED_INT, meshArray[i]);
        gl.glEndList();
  }

ERROR:
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x1CEEFC84
Function=DrvSetLayerPaletteEntries+0x138E34
Library=C:\WINNT\System32\i81xgicd.dll

I’ve tryen on other machine…but error is the same …
QUESTION:
1 - Whats wrong?
2 - Do exists a different method for rendering CURVED SURFACE

glDrawElements’ second parameter is the number of primatives to render, not vertices. Replace ‘line’ with

meshArray[i].length - 2

for triangle strips.

No he got it right : glDrawElements’ second parameter is the number of indices to be read from the array.

I have no idea where the problem could come from. And the error message is not really helpful… Do you know if the equivalent C code run on your machine ?

EDIT : Probably a dumb thing to ask but your meshArray contains indices, not vertex data ?

/me squints at OpenGL docs again

Oops, my bad. Odd choice of words in the docs I’ve got here though :-[

In that case, I’d check your indices are right. If they’re too big they could be trying to reference some arbitrary point in memory (hence the access violation).

Orangy Tang : The term ‘count’ is quite misleading, they should have called it nbIndices. I googled a bit to be sure before posting :wink:

2late4u : Do you have a gfx card or a on-board graphics controller ? From the message error I’d say the latter. OpenGL drivers for such chipsets can be really crappy, did you have any problem with native apps ?

Does each one of your “lines” in your mesh array have the same number of indices? Also, check to make sure that your array pointers are valid, and have enough vertices to match up with your indices.

I have got a Radeon 9600Pro … but the code … hit down with the same error… on Nvidia 5200Fx and radeon 9100 too …
damned

the method works fine for other surface …

Post more code! It would be nice to see how you create and fill those mesh arrays. And how you create and bind your vertex/texCoord arrays as well.


int line = meshArray[0].length;
 
   for (int i = 0; i < total;  i++)
   gl.glDrawElements(gl.GL_TRIANGLE_STRIP, line, gl.GL_UNSIGNED_INT, meshArray[i]); 

are you really sure, you want to say meshArray[0].length? Effectively using the same length for all your arrays?
I think you need to get the length for each array-entry in the for-loop.
Or do all of them have exactly the same length?

… the generic algorithm approssimation must be like this



int line;  
   for (int i = 0; i < total;  i++) 
   {
          line = meshArray[i].length; 
          gl.glDrawElements(gl.GL_TRIANGLE_STRIP, line, gl.GL_UNSIGNED_INT, meshArray[i]);
    }  


but the error is the same …

Can you post your vertex-arrays setup code?
Maybe the error is there.

this is the vertex array setup … but the bug cannot be in this code … infact it works fine with FlatSurface and Mesh … it fails only with Patch surface …

      public void prepareArray(GL gl, int flags) {

    gl.glClientActiveTextureARB(gl.GL_TEXTURE0_ARB);
      if ((flags & VERTEX) > 0)
                  gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertBuffer);
        if ((flags & TEXTURE) > 0)
                  gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, texBuffer );
       if ((flags & LIGHTMAP) > 0)
        {
                  gl.glClientActiveTextureARB(gl.GL_TEXTURE1_ARB);
              gl.glEnable(gl.GL_TEXTURE_2D);
                  gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, lmBuffer );
                  gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
            }

          gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
            gl.glActiveTextureARB(gl.GL_TEXTURE1_ARB);
          gl.glTexEnvf (gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE_EXT);

                        // Operator.
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_RGB_EXT, gl.GL_MODULATE);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_ALPHA_EXT, gl.GL_MODULATE );
                      // Arg0.

                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE0_RGB_EXT, gl.GL_PREVIOUS_EXT );
//                      gl.glTexEnvfv(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_COLOR, new float [] { 0.3f, 0.3f, 0.3f, 0.0f} );
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_OPERAND0_RGB_EXT,  gl.GL_SRC_COLOR);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE0_ALPHA_EXT,  gl.GL_PREVIOUS_EXT);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_OPERAND0_ALPHA_EXT, gl.GL_SRC_ALPHA );

                      // Arg1.
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE1_RGB_EXT, gl.GL_TEXTURE);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_OPERAND1_RGB_EXT, gl.GL_SRC_COLOR);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE1_ALPHA_EXT, gl.GL_TEXTURE );
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_OPERAND1_ALPHA_EXT, gl.GL_SRC_ALPHA );

                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE2_RGB_EXT, gl.GL_PRIMARY_COLOR_EXT);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_OPERAND2_RGB_EXT, gl.GL_SRC_COLOR);
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE2_ALPHA_EXT, gl.GL_PRIMARY_COLOR_EXT );
                      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_OPERAND2_ALPHA_EXT, gl.GL_SRC_ALPHA );

      }

The engine works fine … but it doesn’t render curved surface … HELP PLEASE!

this is my MeshSurface Class…


public class MeshSurface extends Surface {
      public int [] mesh;

      int list;
      
      public void draw(GL gl) {
            list = gl.glGenLists(1);
            gl.glNewList(list, gl.GL_COMPILE_AND_EXECUTE);
            gl.glDrawElements(gl.GL_TRIANGLES, mesh.length, gl.GL_UNSIGNED_INT, mesh);
            gl.glEndList();
      }

      public void draw(GL gl, GLU glu, VertexArray vertexArray) {
            gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB);
            gl.glEnable(gl.GL_TEXTURE_2D);

                  gl.glBindTexture(gl.GL_TEXTURE_2D, shader.texture[0]);
                  gl.glCallList(list);
      }
}

and this is the … CurvedSurface class … tha FAILS!!!

public class CurvedSurface extends Surface
{
      public int [][] meshArray = null;
      int list;

    public void draw(GL gl) {
            list = gl.glGenLists(1);
       gl.glNewList(list, gl.GL_COMPILE_AND_EXECUTE);
            int total = meshArray.length;
            int line = meshArray[0].length;

        for (int i = 0; i < total;  i++)
             gl.glDrawElements(gl.GL_TRIANGLES, meshArray[i].length, gl.GL_UNSIGNED_INT, meshArray[i]);
            gl.glEndList();
      }

      
      public void draw(GL gl, GLU glu, VertexArray vertexArray) {
            gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB);
            gl.glEnable(gl.GL_TEXTURE_2D);

                  gl.glBindTexture(gl.GL_TEXTURE_2D, shader.texture[0]);
                  gl.glCallList(list);
      }
}

damned!

You can try to use the IntBuffer based version of glDrawElements. Create a direct int-buffer with jogl’s BufferUtils-class and use that one instead of the int-array.
Direct Buffers are on the native side of JNI, maybe the gc shuffles your int-array around and the pointer is no longer valid, when the GL accesses it after your DrawElements-call has returned.
Maybe your curved-surfaces are bigger than the others and this results in the gc kicking in or something…

Jan