Bugzilla – Attachment 739 Details for
Bug 1225
Nothing is drawn after AWT-Eventqueue thread is interrupted.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
A java class with main method to demo explained behaviour.
InterruptTest.java (text/plain), 4.66 KB, created by
ozgurkurt
on 2015-09-22 15:25:27 CEST
(
hide
)
Description:
A java class with main method to demo explained behaviour.
Filename:
MIME Type:
Creator:
ozgurkurt
Created:
2015-09-22 15:25:27 CEST
Size:
4.66 KB
patch
obsolete
>import java.awt.BorderLayout; >import java.awt.Color; >import java.awt.Component; >import java.awt.Dimension; >import java.awt.Graphics; >import java.awt.GridLayout; >import java.awt.event.MouseEvent; >import java.util.Random; > >import javax.swing.JFrame; >import javax.swing.JPanel; > >import com.jogamp.opengl.GL2; >import com.jogamp.opengl.GLAutoDrawable; >import com.jogamp.opengl.GLEventListener; >import com.jogamp.opengl.awt.GLCanvas; >import com.jogamp.opengl.glu.GLU; > > >/** > * Test class to check if interrupt on AWT-EventQueue causes a malfunction in JOGL. After application > * is started it displays a rectangle in an AWT component, and a triangle on a GLCanvas. After clicking > * on the rectangle, GLCanvas doesn't get drawn. > */ > >public class InterruptTest > extends GLCanvas > implements Runnable, GLEventListener >{ > private static final long serialVersionUID = 1L; > > public static void main(String[] args) > { > JPanel panel = new JPanel(new GridLayout(2, 1)); > > InterruptTest test = new InterruptTest(); > > panel.add(test); > panel.add(test.component); > > JFrame frame = new JFrame(); > > frame.setResizable(true); > frame.setSize(new Dimension(800, 600)); > frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); > frame.setLocationRelativeTo(null); > > frame.getContentPane().add(panel, BorderLayout.CENTER); > frame.setVisible(true); > > Thread thread = new Thread(test); > thread.start(); > } > > Random random = new Random(); > TestComponent component = new TestComponent(); > > public InterruptTest() > { > addGLEventListener(this); > } > > protected void display(GL2 gl) > { > GLU.createGLU(gl).gluLookAt(5, 5, 5, 0, 0, 0, 0, 0, 1); > > gl.glDisable(GL2.GL_LIGHTING); > > gl.glBegin(GL2.GL_TRIANGLES); > gl.glColor4f(getRandf(), getRandf(), getRandf(), 1); > gl.glVertex3d(0, 0, 0); > gl.glVertex3d(1, 0, 0); > gl.glVertex3d(0, 1, 0); > gl.glEnd(); > } > > private float getRandf() > { > return (random.nextInt(100) + 155) / 255f; > } > > @Override > public void run() > { > while(!Thread.interrupted()) > { > try > { > if(random.nextBoolean()) > component.repaint(); > else > display(); > > Thread.sleep(100); > } > catch (InterruptedException e) > { > Thread.currentThread().interrupt(); > } > catch (Exception e) > { > e.printStackTrace(); > } > } > } > > @Override > public void display(GLAutoDrawable glad) > { > GL2 gl = glad.getGL().getGL2(); > > gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); > gl.glLoadIdentity(); > > try > { > display(gl); > } > catch (Throwable throwable) > { > System.err.println("exception during display" + throwable); > } > } > > @Override > public final void init(GLAutoDrawable glad) > { > GL2 gl = glad.getGL().getGL2(); > > gl.glClearColor(1, 1, 1, 1); > gl.glClearDepth(1.0f); > > gl.glEnable(GL2.GL_LIGHTING); > gl.glEnable(GL2.GL_NORMALIZE); > gl.glEnable(GL2.GL_BLEND); > gl.glEnable(GL2.GL_DEPTH_TEST); > > gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); > gl.glDepthFunc(GL2.GL_LEQUAL); > > gl.glShadeModel(GL2.GL_SMOOTH); > > gl.glEnable(GL2.GL_CULL_FACE); > gl.glFrontFace(GL2.GL_CCW); > gl.glCullFace(GL2.GL_BACK); > gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); > } > > @Override > public final void reshape(GLAutoDrawable glad, int x, int y, int width, int height) > { > GL2 gl = glad.getGL().getGL2(); > > float aspectRatio = (float) width / (float) height; > > gl.glViewport(0, 0, width, height); > > gl.glMatrixMode(GL2.GL_PROJECTION); > gl.glLoadIdentity(); > > GLU.createGLU(gl).gluPerspective(30, aspectRatio, 0.5, 50); > > gl.glMatrixMode(GL2.GL_MODELVIEW); > gl.glLoadIdentity(); > } > > @Override > public void dispose(GLAutoDrawable glad) > { > } > > public class TestComponent > extends Component > { > private static final long serialVersionUID = 1L; > > private volatile boolean interrupt = false; > > public TestComponent() > { > enableEvents(MouseEvent.MOUSE_EVENT_MASK); > } > > @Override > protected void processMouseEvent(MouseEvent me) > { > if(me.getID() == MouseEvent.MOUSE_CLICKED) > interrupt = true; > } > > @Override > public void paint(Graphics g) > { > g.setColor(new Color(getRandf(), getRandf(), getRandf())); > g.fillRect(10, 10, 100, 100); > > if(interrupt) > { > interrupt = false; > Thread.currentThread().interrupt(); > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1225
: 739