Error: Share a GLContext from a GLCanvas to a GLJPanel

I share the GLContext from the main opengl scene in a GLCanvas with a secondary scene in a GLJPanel (for swing integration).

All is going well until the GLJPanel is resized. The resize event generate the exception below.

It appends with JSR-231 1.1.0 rc3 and the last nightly build (27/03/2007). Notice that if I use a GLCanvas instead of a GLJPanel, this does not occures.

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: wglShareLists(0x10000, 0x10002) failed: error code 0
	at com.sun.opengl.impl.windows.WindowsGLContext.create(WindowsGLContext.java:136)
	at com.sun.opengl.impl.windows.WindowsGLContext.makeCurrentImpl(WindowsGLContext.java:150)
	at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:182)
	at javax.media.opengl.GLJPanel.paintComponent(GLJPanel.java:607)
	at javax.swing.JComponent.paint(JComponent.java:1022)
	at javax.swing.JComponent.paintChildren(JComponent.java:859)
	at javax.swing.JComponent.paint(JComponent.java:1031)
	at javax.swing.JComponent.paintChildren(JComponent.java:859)
	at javax.swing.JComponent.paint(JComponent.java:1031)
	at javax.swing.JComponent.paintChildren(JComponent.java:859)
	at javax.swing.JComponent.paint(JComponent.java:1031)
	at javax.swing.JComponent.paintChildren(JComponent.java:859)
	at javax.swing.JComponent.paint(JComponent.java:1031)
	at javax.swing.JComponent.paintChildren(JComponent.java:859)
	at javax.swing.JComponent.paint(JComponent.java:1031)
	at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
	at javax.swing.JComponent.paintChildren(JComponent.java:859)
	at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)
	at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
	at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
	at javax.swing.JComponent.paint(JComponent.java:1008)
	at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
	at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
	at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
	at java.awt.Container.paint(Container.java:1797)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
	at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Can you boil this down into a small test case and either post it or file a bug with the Issue Tracker on the JOGL home page?

Ok, I will post a simple test case soon.

Here is the small test :wink:


import java.awt.event.*;
import javax.swing.JFrame;

import javax.media.opengl.*;
import javax.media.opengl.glu.GLU;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;

public class GLContextSharing extends JFrame
{
	public static void main(String[] args)
	{
		new GLContextSharing().setVisible(true);
	}
	
	private GLCanvas glScene = null;
	private JPanel jContentPane = null;
	private JButton jCanvasB = null;
	private JButton jPanelB = null;

	public GLContextSharing()
	{
		super("Resizing a GLJPanel");
		initialize();
	}

	private void initialize()
	{
        this.setContentPane(getJContentPane());
		this.pack();
		this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	private JPanel getJContentPane()
	{
		if(jContentPane == null)
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanelB(), BorderLayout.NORTH);
			jContentPane.add(getGlScene(), BorderLayout.CENTER);
			jContentPane.add(getJCanvasB(), BorderLayout.SOUTH);
		}
		return jContentPane;
	}
	private JButton getJCanvasB()
	{
		if(jCanvasB == null)
		{
			jCanvasB = new JButton();
			jCanvasB.setText("Share GLContext with a GLCanvas");
			jCanvasB.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					GLCanvas glCanvas = new GLCanvas(null, null,
							getGlScene().getContext(),
							getGlScene().getGraphicsConfiguration().getDevice());
				    glCanvas.addGLEventListener(new Scene());
				    
				    JFrame frame = new JFrame("GLCanvas");
				    frame.add(glCanvas);
				    frame.setSize(200, 200);
				    frame.setVisible(true);
				    
				    Animator animator = new Animator(glCanvas);
				    animator.start();
				}
			});
		}
		return jCanvasB;
	}
	private JButton getJPanelB()
	{
		if(jPanelB == null)
		{
			jPanelB = new JButton();
			jPanelB.setText("Share GLContext with a GLJPanel");
			jPanelB.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
				    GLJPanel gljPanel = new GLJPanel(null, null,
				    		getGlScene().getContext());
				    gljPanel.addGLEventListener(new Scene());
				    
				    JFrame frame = new JFrame("GLJPanel [Try resizing the window]");
				    frame.add(gljPanel);
				    frame.setSize(200, 200);
				    frame.setVisible(true);
				    
				    Animator animator = new Animator(gljPanel);
				    animator.start();
				}
			});
		}
		return jPanelB;
	}
	private GLCanvas getGlScene()
	{
		if(glScene == null)
		{
			glScene = new GLCanvas();
			glScene.addGLEventListener(new Scene());
			glScene.setSize(400, 300);
		}
		return glScene;
	}
	
	private static int DISPLAY_LIST = -1;
	class Scene implements GLEventListener
	{
		private Animator animator;

		public void displayChanged(GLAutoDrawable glDrawable, boolean modeChanged, boolean deviceChanged){}
		public void reshape(GLAutoDrawable glDrawable, int x, int y, int width, int height)
		{
			final GL gl = glDrawable.getGL();
			final GLU glu = new GLU();

			if(height <= 0) height = 1;

			gl.glViewport(0, 0, width, height);
			gl.glMatrixMode(GL.GL_PROJECTION);
			gl.glLoadIdentity();
			glu.gluPerspective(45.0f, width / height, 0.1f, 1000.0f);
			gl.glMatrixMode(GL.GL_MODELVIEW);
			gl.glLoadIdentity();
		}

		public void init(GLAutoDrawable glDrawable)
		{
			final GL gl = glDrawable.getGL();
			
			gl.glEnable(GL.GL_LIGHT0);
			gl.glEnable(GL.GL_LIGHTING);
			gl.glDepthFunc(GL.GL_LEQUAL);
			gl.glEnable(GL.GL_DEPTH_TEST);
			
			if(DISPLAY_LIST == -1)
			{
				DISPLAY_LIST = gl.glGenLists(1);
				gl.glNewList(DISPLAY_LIST, GL.GL_COMPILE);
					gl.glColor3f(0.5f, 0.5f, 0.5f);
					new GLUT().glutSolidTeapot(1.0f);
				gl.glEndList();
			}
			
			animator = new Animator(glDrawable);
			animator.start();
		}
		
		public void display(GLAutoDrawable glDrawable)
		{
			final GL gl = glDrawable.getGL();
			
			gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
			gl.glLoadIdentity();
			gl.glTranslatef(0.0f, 0.0f, -5.0f);
			
			if(gl.glIsList(DISPLAY_LIST))
				gl.glCallList(DISPLAY_LIST);
		}
	}
}

Your test works fine on my machine (Windows XP SP2, NVidia Quadro FX Go 700 mobile chip, close to 4 years old). Check for updates to your OpenGL drivers from your graphics card’s vendor. What graphics card do you have in your machine?

I’ve got an ATI Radeon 9600, under windows 2000.
I’ve also tried in another machine with an ATI Rage 128 (also under Windows 2000) : same error.

I will try with an Nvidia …

Edit: with an nvidia card, it’s ok.
I will try with the last ati driver in date to know if this fix the problem.

The last ati driver fix this problem :slight_smile: