Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  glDrawElements() unexplained ERROR!  (Read 3477 times)
0 Members and 1 Guest are viewing this topic.
Offline 2late4u

JGO n00b
*

Posts: 30


.....


« on: 2004-03-24 00:15:55 »

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 Sad)
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);
           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
Offline Orangy Tang

JGO Kernel
*****

Posts: 2960
Medals: 37


Monkey for a head


« Reply #1 on: 2004-03-24 02:26:34 »

glDrawElements' second parameter is the number of primatives to render, not vertices. Replace 'line' with
1  
meshArray[i].length - 2

for triangle strips.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline overnhet

Jr. Member
**

Posts: 90


Java games rock!


« Reply #2 on: 2004-03-24 03:08:39 »

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 ?
Games published by our own members! Go get 'em!
Offline Orangy Tang

JGO Kernel
*****

Posts: 2960
Medals: 37


Monkey for a head


« Reply #3 on: 2004-03-24 03:21:11 »

/me squints at OpenGL docs again

Oops, my bad. Odd choice of words in the docs I've got here though Embarrassed

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).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline overnhet

Jr. Member
**

Posts: 90


Java games rock!


« Reply #4 on: 2004-03-24 04:19:55 »

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 ?
Offline milvich

JGO n00b
*

Posts: 44


Java games rock!


« Reply #5 on: 2004-03-24 07:21:18 »

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.
Offline 2late4u

JGO n00b
*

Posts: 30


.....


« Reply #6 on: 2004-03-24 08:21:17 »

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 ...
Offline Orangy Tang

JGO Kernel
*****

Posts: 2960
Medals: 37


Monkey for a head


« Reply #7 on: 2004-03-24 08:59:01 »

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.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline jeickmann

Jr. Member
**

Posts: 51


Java games rock!


« Reply #8 on: 2004-03-24 10:27:21 »

1  
2  
3  
4  
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?
Offline 2late4u

JGO n00b
*

Posts: 30


.....


« Reply #9 on: 2004-03-24 22:56:24 »

.... the generic algorithm approssimation must be like this

1  
2  
3  
4  
5  
6  
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 ....
Games published by our own members! Go get 'em!
Offline jeickmann

Jr. Member
**

Posts: 51


Java games rock!


« Reply #10 on: 2004-03-25 00:20:22 »

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

JGO n00b
*

Posts: 30


.....


« Reply #11 on: 2004-03-25 08:58:56 »


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 ....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
      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!
Offline 2late4u

JGO n00b
*

Posts: 30


.....


« Reply #12 on: 2004-03-25 09:03:00 »

this is my MeshSurface Class.....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
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);
      }
}
Offline 2late4u

JGO n00b
*

Posts: 30


.....


« Reply #13 on: 2004-03-25 09:04:52 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
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!
Offline jeickmann

Jr. Member
**

Posts: 51


Java games rock!


« Reply #14 on: 2004-03-26 06:37:07 »

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
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.133 seconds with 21 queries.