Application crashes on ati video cards, uses java, jogl, and textures.

I have an application that runs flawlessly (well nearly so) on nvidia video cards, but on ati cards, some time after a texture has been placed on a surface, the jvm crashes, and it blames either the ati driver, or a kernel sys call. I managed to recreate it in a relatively simple bit of code: note I am using display lists for better performance. If you take the following code (up/down rotates, enter flops the textures) and run it spinning and flopping it for a couple minutes, it crashes.



package org.yourorghere;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;



/**
 * SimpleJOGL.java 

 * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */
public class SimpleJOGL implements GLEventListener, KeyListener {

    GLCanvas canvas;
    int lists;
    float angle = 0.f;
    boolean needsRotate = false;
    boolean needsTexture = false;
    Texture texture1;
    Texture texture2;
        
    Color c1 = Color.red;
    Color c2 = Color.green;
    
    public SimpleJOGL(GLCanvas canvas) {
        this.canvas = canvas;
    }

    public static void main(String[] args) {
        Frame frame = new Frame("Simple JOGL Application");
        GLCanvas canvas = new GLCanvas();

        SimpleJOGL sjogl = new SimpleJOGL(canvas);
        canvas.addKeyListener(sjogl);
        
        canvas.addGLEventListener(sjogl);
        frame.add(canvas);
        frame.setSize(640, 480);
        final Animator animator = new Animator(canvas);
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
                // make sure the call to Animator.stop() completes before
                // exiting
                new Thread(new Runnable() {

                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        // Center frame
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();
    }

    public void init(GLAutoDrawable drawable) {
        // Use debug pipeline
        // drawable.setGL(new DebugGL(drawable.getGL()));

        GL gl = drawable.getGL();
        System.err.println("INIT GL IS: " + gl.getClass().getName());

        // Enable VSync
        gl.setSwapInterval(1);

        // double buffer
        gl.glEnable(GL.GL_DOUBLEBUFFER);
        drawable.setAutoSwapBufferMode(false);
        
        // Enable VSync
        gl.setSwapInterval(1);
        
        // Setup the drawing area and shading mode
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
        
        gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
        gl.glEnable(GL.GL_TEXTURE_2D);
        gl.glDisable(GL.GL_BLEND);
        
                // -- lighting --
        gl.glEnable(GL.GL_COLOR_MATERIAL);
        gl.glLightModelf(GL.GL_LIGHT_MODEL_TWO_SIDE, 1.0f);
        gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
        gl.glEnable(GL.GL_MAP1_VERTEX_3);
        gl.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, new float[]{.3f,.3f,.3f,1.f},0);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, new float[]{.55f,.55f,.55f,1.f},0);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, new float[]{.05f,.05f,.05f,1.f}, 0);
        gl.glFrontFace(GL.GL_CCW);
        gl.glEnable(GL.GL_LIGHT0);
        gl.glEnable(GL.GL_LIGHTING);
        gl.glEnable(GL.GL_DEPTH_TEST);

        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[]{.5f,.5f,.5f,1.0f}, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[]{.05f, .05f, .05f, 1.0f}, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, new float[]{0.01f, 0.01f, 0.01f, 1.f}, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, new float[]{30}, 0);
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_COLOR_INDEXES, new float[]{1.0f, 0.0f, 0.0f, 1.0f}, 0);
        
        gl.glCullFace(GL.GL_BACK);
        gl.glDisable(GL.GL_BLEND);
        gl.glEnable(GL.GL_RESCALE_NORMAL);

        
        lists = gl.glGenLists(3);
        this.needsRotate = true;
        this.needsTexture = true;
    }
    
    private void reTexture(GL gl) {
        BufferedImage image1 = makeImage(c1);
        BufferedImage image2 = makeImage(c2);
        makeShape(gl, image1, image2);
    }
    private BufferedImage makeImage(Color c) {
        int y = 1200;
        int x = 1024;
        BufferedImage image = new BufferedImage(y, y, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = image.createGraphics();
        g.setBackground(Color.white);
        g.clearRect(0, 0, y,y);
        Rectangle2D r = new Rectangle2D.Float(128,128,x-256,x-256);
        g.setColor(c);
        g.fill(r);
        g.dispose();
        return image;
    }

    private void makeShape(GL gl, BufferedImage image1, BufferedImage image2) {
        float x = 1024.f/1200.f;

        texture1 = TextureIO.newTexture(image1, false) ;
        texture2 = TextureIO.newTexture(image2, false) ;
        
        gl.glNewList(lists+1, GL.GL_COMPILE);
                
        gl.glColor3f(0f, .8f, .4f);
        // Drawing Using Triangles

        gl.glBegin(GL.GL_POLYGON);
            gl.glTexCoord2f(0, 0);
            gl.glVertex3f(0.0f, 0.0f, 0.0f);   // Top
            gl.glNormal3f(0, 0, 1);
            
            gl.glTexCoord2f(x, 0);
            gl.glVertex3f(1.0f, 0.0f, 0.0f); // Bottom Left
            gl.glNormal3f(0, 0, 1);
            
            gl.glTexCoord2f(x, x);
            gl.glVertex3f(1.0f, 1.0f, 0.0f);  // Bottom Right
            gl.glNormal3f(0, 0, 1);
            
            gl.glTexCoord2f(0, x);
            gl.glVertex3f(0f, 1.0f, 0.0f);  // Bottom Right
            gl.glNormal3f(0, 0, 1);
        gl.glEnd();
        texture1.disable();
        
        gl.glEndList();
        
        gl.glNewList(lists+2, GL.GL_COMPILE);
        
        texture2.enable();
        texture2.bind();
        gl.glBegin(GL.GL_POLYGON);
            gl.glTexCoord2f(0, 0);
            gl.glVertex3f(0.0f, 0.0f, 0.0f);   // Top
            gl.glNormal3f(0, 0, 1);
            
            gl.glTexCoord2f(x, 0);
            gl.glVertex3f(1.0f, 0.0f, 0.0f); // Bottom Left
            gl.glNormal3f(0, 0, 1);
            
            gl.glTexCoord2f(x, x);
            gl.glVertex3f(1.0f, -1.0f, 0.0f);  // Bottom Right
            gl.glNormal3f(0, 0, 1);
            
            gl.glTexCoord2f(0, x);
            gl.glVertex3f(0f, -1.0f, 0.0f);  // Bottom Right
            gl.glNormal3f(0, 0, 1);
        gl.glEnd();
        texture2.disable();
        
        gl.glEndList();


    }
    
    public void rotate(GL gl) {
        gl.glNewList(lists, GL.GL_COMPILE);

        gl.glLoadIdentity();
        gl.glTranslatef(-2.f, 0.f, -6.f);
        gl.glRotatef(angle, 1.0f, 0.f, 0.f);
                
        gl.glCallList(lists+1);
        
        gl.glRotatef(-45, 1.f, 0.f, 0.f);
        
        gl.glCallList(lists+2);        
        gl.glEndList();
    }
    
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL gl = drawable.getGL();
        GLU glu = new GLU();

        if (height <= 0) { // avoid a divide by zero error!
        
            height = 1;
        }
        final float h = (float) width / (float) height;
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(45.0f, h, 1.0, 20.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        
        if (needsTexture) {
            reTexture(gl);
            needsTexture = false;
        }

        
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[]{1.f, 1.f, 1.f, 0.f}, 0);

        
        gl.glLoadIdentity();
        gl.glTranslatef(-2.f, 0.f, -6.f);
        gl.glRotatef(angle, 1.0f, 0.f, 0.f);
                
                texture1.enable();
        texture1.bind();
        gl.glCallList(lists+1);
        texture1.disable();
        
        gl.glRotatef(-45, 1.f, 0.f, 0.f);
        
        gl.glCallList(lists+2);      
        
//        
//        if (needsRotate) {
//            rotate(gl);
//            needsRotate = false;
//        }
//        
//        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
//
//        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[]{1.f, 1.f, 1.f, 0.f}, 0);

        
//        gl.glCallList(lists);
        

        // Flush all drawing operations to the graphics card
        drawable.swapBuffers();
    }

    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }

    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
            angle -= 5;
            needsRotate = true;

        } 
        if (e.getKeyCode() == KeyEvent.VK_UP) {
            angle += 5;
            needsRotate = true;
        }
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            Color c = c1;
            c1 = c2;
            c2 = c;
            needsTexture = true;
        }
    }

    public void keyReleased(KeyEvent e) {
    }

    public void keyTyped(KeyEvent e) {
        canvas.repaint();
    }
    
    
}

thank you!
–Douglas

I could not compile this without libraries, and asking for us to run things without providing the tools is too much hassle :stuck_out_tongue:

Everyone knows ATI can’t make proper drivers to save their lives.

The only libraries I am using are the JOGL pack, and I don’t get to choose the graphics cards people run my application on. I figure I’m setting something up wrong since it can’t possibly be that display lists and textures are incompatible on all ATI cards.

Avoid display lists at all costs.

Cas :slight_smile:

Hi

Rather use JOGL 2.0 and anyway, princec is right, avoid using display lists. Even on a very few NVIDIA consumer graphics cards (not those of the Quadro FX series) you might have the same problem. You should have posted this question in the JOGL section.