native code crashes

could someone please tell me why my program, which for now simply rotates a cylinder, crashes after 2 seconds? Here it is:


import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;

public class Pipes extends Frame{
      Animator animator;
      GLCanvas canvas;
      Pipes pipeFrame;
      public Pipes(){
            setTitle("3D Pipes program --Daniel D. Marino");
            canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
            canvas.addGLEventListener(new Renderer());
            add(canvas);
            animator = new Animator(canvas);
            setSize(640, 480);
            setResizable(false);
            addWindowListener(new WindowAdapter(){
                  public void windowClosing(WindowEvent e){
                        animator.stop();
                         System.exit(0);
                  }
          });
          setVisible(true);
          animator.start();
          canvas.requestFocus();
          pipeFrame = this;
      }
      
      
      private class Renderer implements GLEventListener{
            private float rquad = 0.0f;
          private float rtri = 0.0f;
      
            //GLDrawable is the OpenGL canvas?
          public void display(GLDrawable glDrawable){  
                final GL gl = glDrawable.getGL();
                final GLU glu = glDrawable.getGLU();
                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                /*
                gl.glLoadIdentity();
                gl.glTranslatef(-1.5f, 0.0f, -6.0f);
                  gl.glRotatef(rtri, 0.0f, 1.0f, 0.0f);
                  gl.glBegin(GL.GL_TRIANGLES);                // Drawing Using Triangles
              gl.glColor3f(1.0f, 0.0f, 0.0f);   // Set the current drawing color to red
              gl.glVertex3f( 0.0f, 1.0f, 0.0f);      // Top
              gl.glColor3f(0.0f, 1.0f, 0.0f);   // Set the current drawing color to green
              gl.glVertex3f(-1.0f,-1.0f, 0.0f);      // Bottom Left
              gl.glColor3f(0.0f, 0.0f, 1.0f);   // Set the current drawing color to blue
              gl.glVertex3f( 1.0f,-1.0f, 0.0f);      // Bottom Right
                  gl.glEnd();                        // Finished Drawing The Triangle
                  
                  gl.glLoadIdentity();
                  gl.glTranslatef(1.5f, 0.0f, -6.0f);
                  gl.glRotatef(rquad, 1.0f, 0.0f, 0.0f);
                  gl.glBegin(GL.GL_QUADS);                 // Draw A Quad
              gl.glColor3f(0.5f, 0.5f, 1.0f);   // Set the current drawing color to light blue
              gl.glVertex3f(-1.0f, 1.0f, 0.0f);      // Top Left
              gl.glVertex3f( 1.0f, 1.0f, 0.0f);      // Top Right
              gl.glVertex3f( 1.0f,-1.0f, 0.0f);      // Bottom Right
              gl.glVertex3f(-1.0f,-1.0f, 0.0f);      // Bottom Left
                  gl.glEnd();                        // Done Drawing The Quad
                  */
                  
                  gl.glLoadIdentity();
                  gl.glTranslatef(1.5f, 0.0f, -16.0f);
                  gl.glRotatef(rtri, 0.0f, 1.0f, 0.0f);
                  
                  //gl.glBegin(GL.GL_QUADS); 
                  gl.glColor3f(0.0f, 0.0f, 1.0f);
                  
                  GLUquadric quad = new GLUquadric();
                  glu.gluQuadricDrawStyle(quad, glu.GLU_FILL); 
                glu.gluCylinder(quad, 1, 1, 3, 23, 1); 

                  
                  //glDrawable.getGLU().gluCylinder(new GLUquadric(), 5, 5, 1, 20, 4);      
                  
                  //gl.glEnd();
                  
                  gl.glFlush();
                  rtri += 0.2f;
                  rquad += 0.15f;
            }
            
            public void drawStraightPipe(GLDrawable glDrawable, int x, int y) { 
            final GL gl=glDrawable.getGL(); 
            final GLU glu=glDrawable.getGLU(); 
            gl.glLoadIdentity(); 
            gl.glTranslatef((float)(x*10.0f), (float)(y*10.0f), 0.0f); 
            glu.gluCylinder(new GLUquadric(), 5.0, 5.0, 10.0, 10, 1); 
            }
          
          //never use this
            public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, 
                  boolean deviceChanged){
          }
          
             /** Called by the drawable immediately after the OpenGL context is 
          * initialized for the first time. Can be used to perform one-time OpenGL 
          * initialization such as setup of lights and display lists.
          * @param gLDrawable The GLDrawable object.
          */
          public void init(GLDrawable gLDrawable){
                final GL gl = gLDrawable.getGL();
                gl.glShadeModel(GL.GL_SMOOTH);              // Enable Smooth Shading
                gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
                
                  gl.glClearDepth(1.0f);                      // Depth Buffer Setup
                  gl.glEnable(GL.GL_DEPTH_TEST);                                          // Enables Depth Testing
                  gl.glDepthFunc(GL.GL_LEQUAL);                                                // The Type Of Depth Testing To Do
                  gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);      // Really Nice Perspective Calculations
                  
                  gLDrawable.addKeyListener(new KeyListener(){
                        public void keyPressed(KeyEvent e){
                        }
                        public void keyReleased(KeyEvent e){
                        }
                        public void keyTyped(KeyEvent e){
                        }
                  });
          }
          
              
            public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height){
                final GL gl = gLDrawable.getGL();
                final GLU glu = gLDrawable.getGLU();
                  
                if (height <= 0) height = 1;  // avoid a divide by zero error!
                final float h = (float)width / (float)height;
                //gl.glViewport(0, 0, width, height);  //unnecessary
                gl.glMatrixMode(GL.GL_PROJECTION);
                gl.glLoadIdentity();
                glu.gluPerspective(45.0f, h, 1.0, 20.0);
                gl.glMatrixMode(GL.GL_MODELVIEW);
                gl.glLoadIdentity();
          }
      }

      public static void main(String[] args){
          Pipes pipes = new Pipes();
        }
}

What message do you get when it crashes? Please post any output in full.

I imagine I have the same error some months later.

by adding this code to my rendering loop:

      
            // draw cylinder
            gl.glBegin( GL.GL_QUADS );
            gl.glColor4f( .8f, .1f, .8f, .05f); // half transparent
            GLUquadric quad = new GLUquadric(); 
            glu.gluQuadricDrawStyle(quad, GLU.GLU_FILL);  
            glu.gluCylinder(quad, 1, 1, 3, 10, 3); 
            glu.gluDeleteQuadric( quad );
            gl.glEnd();
            

I get this error:
`
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x77F584AE
Function=RtlAllocateHeap+0x900
Library=C:\WINDOWS\System32\ntdll.dll

Current Java thread:
at sun.misc.Unsafe.allocateMemory(Native Method)
at java.nio.DirectByteBuffer.(DirectByteBuffer.java:57)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:283)
at net.java.games.gluegen.runtime.BufferFactory.newDirectByteBuffer(BufferFactory.java:46)
at net.java.games.jogl.GLUquadric.(GLUquadric.java:22)
at demos.nehe.lesson25.Renderer.drawGLScene(Renderer.java:243)
at demos.nehe.lesson25.Renderer.display(Renderer.java:214)
at demos.common.GLDisplay$MyHelpOverlayGLEventListener.display(GLDisplay.java:276)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:194)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:192)
- locked <0777CAD0> (a net.java.games.jogl.impl.windows.WindowsOnscreenGLContext)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
at demos.common.FPSAnimator$RenderRunnable.run(FPSAnimator.java:168)
at java.lang.Thread.run(Thread.java:536)

Dynamic libraries:
0x00400000 - 0x00407000 C:\Program Files\Java\j2re1.4.1_03\bin\javaw.exe
0x77F50000 - 0x77FF7000 C:\WINDOWS\System32\ntdll.dll
0x77E60000 - 0x77F46000 C:\WINDOWS\system32\kernel32.dll
0x77DD0000 - 0x77E5D000 C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78086000 C:\WINDOWS\system32\RPCRT4.dll
0x77D40000 - 0x77DCC000 C:\WINDOWS\system32\USER32.dll
0x77C70000 - 0x77CB0000 C:\WINDOWS\system32\GDI32.dll
0x77C10000 - 0x77C63000 C:\WINDOWS\system32\MSVCRT.dll
0x629C0000 - 0x629C8000 C:\WINDOWS\System32\LPK.DLL
0x72FA0000 - 0x72FFA000 C:\WINDOWS\System32\USP10.dll
0x6D340000 - 0x6D46B000 C:\Program Files\Java\j2re1.4.1_03\bin\client\jvm.dll
0x76B40000 - 0x76B6C000 C:\WINDOWS\System32\WINMM.dll
0x6BD00000 - 0x6BD0D000 C:\WINDOWS\System32\SYNCOR11.DLL
0x6D1E0000 - 0x6D1E7000 C:\Program Files\Java\j2re1.4.1_03\bin\hpi.dll
0x6D310000 - 0x6D31E000 C:\Program Files\Java\j2re1.4.1_03\bin\verify.dll
0x6D220000 - 0x6D239000 C:\Program Files\Java\j2re1.4.1_03\bin\java.dll
0x6D330000 - 0x6D33D000 C:\Program Files\Java\j2re1.4.1_03\bin\zip.dll
0x6D000000 - 0x6D105000 C:\Program Files\Java\j2re1.4.1_03\bin\awt.dll
0x73000000 - 0x73023000 C:\WINDOWS\System32\WINSPOOL.DRV
0x76390000 - 0x763AC000 C:\WINDOWS\System32\IMM32.dll
0x771B0000 - 0x772D1000 C:\WINDOWS\system32\ole32.dll
0x5AD70000 - 0x5ADA4000 C:\WINDOWS\System32\uxtheme.dll
0x6D190000 - 0x6D1E0000 C:\Program Files\Java\j2re1.4.1_03\bin\fontmanager.dll
0x51000000 - 0x51047000 C:\WINDOWS\System32\ddraw.dll
0x73BC0000 - 0x73BC6000 C:\WINDOWS\System32\DCIMAN32.dll
0x5C000000 - 0x5C0C8000 C:\WINDOWS\System32\D3DIM700.DLL
0x74720000 - 0x74764000 C:\WINDOWS\System32\MSCTF.dll
0x3B380000 - 0x3B387000 C:\Program Files\Yahoo!\Messenger\idle.dll
0x77120000 - 0x771AB000 C:\WINDOWS\system32\OLEAUT32.DLL
0x6D240000 - 0x6D245000 C:\Program Files\Java\j2re1.4.1_03\bin\jawt.dll
0x3B390000 - 0x3B406000 D:\jogl\jogl-win32\jogl.dll
0x5ED00000 - 0x5EDC6000 C:\WINDOWS\System32\OPENGL32.dll
0x68B20000 - 0x68B3E000 C:\WINDOWS\System32\GLU32.dll
0x69000000 - 0x69388000 C:\WINDOWS\System32\atioglxx.dll
0x76C90000 - 0x76CB2000 C:\WINDOWS\system32\imagehlp.dll
0x6D510000 - 0x6D58D000 C:\WINDOWS\system32\DBGHELP.dll
0x77C00000 - 0x77C07000 C:\WINDOWS\system32\VERSION.dll
0x76BF0000 - 0x76BFB000 C:\WINDOWS\System32\PSAPI.DLL

Local Time = Wed Feb 11 18:31:56 2004
Elapsed Time = 7

The exception above was detected in native code outside the VM

Java VM: Java HotSpotâ„¢ Client VM (1.4.1_03-b02 mixed mode)

#`

You need to use glu.gluNewQuadric(), as in C, rather than calling the GLUQuadric constructor by hand (new GLUQuadric())

It works! Woohoo! Thanks so much.