I have a JavaFX application which contains a SwingNode with an OpenGL app in it.
Most of the time, everything is fine, but sometimes when I close the window I get this error:
Catched Exception on thread AWT-EventQueue-0
javax.media.nativewindow.NativeWindowException: DC not released: GDISurface[ displayHandle 0x0
, surfaceHandle 0xffffffffe201277c
, size 2560x1361
, UOB[ OWNS_SURFACE | OWNS_DEVICE | WINDOW_INVISIBLE ]
, WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 7, ARB-Choosen true,
requested GLCaps[rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/0/0, one, mono , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
chosen GLCaps[wgl vid 7 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/0/0, one, mono , hw, GLProfile[GL4bc/GL4bc.hw], offscr[fbo]]]
, surfaceLock <4a7b3290, 6de653ec>[count 1, qsz 0, owner <AWT-EventQueue-0>]
, GDIDummyUpstreamSurfaceHook[ 2560x1361]
, upstreamSurface false ], isWindow false, werr 0, thread: AWT-EventQueue-0
at jogamp.nativewindow.windows.GDISurface.unlockSurfaceImpl(GDISurface.java:121)
at jogamp.nativewindow.ProxySurfaceImpl.unlockSurface(ProxySurfaceImpl.java:226)
at jogamp.opengl.GLDrawableImpl.unlockSurface(GLDrawableImpl.java:334)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:354)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:316)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1132)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at javax.media.opengl.awt.GLJPanel$OffscreenBackend.doPaintComponent(GLJPanel.java:1731)
at javax.media.opengl.awt.GLJPanel.paintComponent(GLJPanel.java:538)
at javax.swing.JComponent.paint(JComponent.java:1056)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at sun.swing.JLightweightFrame$3.paint(JLightweightFrame.java:309)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
at javax.swing.RepaintManager.paint(RepaintManager.java:1275)
at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
at javax.swing.JComponent.paintImmediately(JComponent.java:4950)
at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I searched what it could be about, but I can't find anything. Does anybody have an idea of why this happens ? Here is the code I use to close the app:
// Close operation
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent t) {
Platform.exit();
System.exit(0);
}
});
i am not sure but you are doing Platform.exit() that force Application.lauch() to return so you should put System.exit() in the main() function, because JavaFX runtime close when you do Platform.exit() and stop() method is called but in the same time System.exit() is called
Related
In Java why do I get java.lang.IllegalStateException: cannot open system clipboard ?
This was running on Windows using Java 1.8.0_181 25.181-b13
java.lang.IllegalStateException: cannot open system clipboard
at sun.awt.windows.WClipboard.openClipboard(Native Method)
at sun.awt.datatransfer.SunClipboard.getClipboardFormatsOpenClose(SunClipboard.java:327)
at sun.awt.datatransfer.SunClipboard.isDataFlavorAvailable(SunClipboard.java:188)
at com.jthink.songkong.ui.startdialog.editsongs.EditSongsTable$PasteAction$1.flavorsChanged(EditSongsTable.java:170)
at sun.awt.datatransfer.SunClipboard$1SunFlavorChangeNotifier.run(SunClipboard.java:441)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
PasteAction methods is
public PasteAction(JTable tbl)
{
putValue(NAME, TextLabel.PASTEBUTTON.getMsg());
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
table = tbl;
final Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.addFlavorListener(new FlavorListener()
{
#Override
public void flavorsChanged(FlavorEvent e)
{
try
{
setEnabled(cb.isDataFlavorAvailable(CellTransferable.CELL_DATA_FLAVOR)
|| cb.isDataFlavorAvailable(DataFlavor.stringFlavor));
}
catch(IllegalArgumentException iae)
{
MainWindow.logger.log(Level.SEVERE, iae.getMessage(), iae);
}
}
});
setEnabled(cb.isDataFlavorAvailable(CellTransferable.CELL_DATA_FLAVOR)
|| cb.isDataFlavorAvailable(DataFlavor.stringFlavor));
}
This happens when the Java app is notified that it has lost ownership, so it sometimes needs to allow a small amount of time for the clipboard to be "ready." By adding a very short sleep command to the method, we will be able to avoid the runtime exceptions. Please go to below link for more information
https://coderanch.com/t/377833/java/listen-clipboard
I want to make a documentListener that if I type in the JTextField : txt_ip4class and match regex of IPv4 format it will change the JComboBox : box_ip4class content.
If the content is changed (itemStateChanged), range of IP Class will be written down to JTextField : txt_rangeclass, and bit usage will be write down to `JTextField : txt_bitclass``*.
I have succeeded in this method, but with a classic method (using jButton), but I failed in this method using documentListener. Only JComboBox : box_ip4Class changed.
My code, applying documentListener to txt_ip4class:
txt_ip4class.getDocument().addDocumentListener(new DocumentListener() {
#Override
public void insertUpdate(DocumentEvent e) {
logUpdate();
}
#Override
public void removeUpdate(DocumentEvent e) {
logUpdate();
}
#Override
public void changedUpdate(DocumentEvent e) {
logUpdate();
}
void logUpdate() {
Runnable doHighlight = new Runnable() {
#Override
public void run() {
String aTxt = txt_ip4class.getText();
classValue = 1;
if (!aTxt.matches("\\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}\\b")) {
classValue = 0;
} else if (aTxt.matches("\\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}\\b")) {
try {
classW.classMain(classValue, box_ip4class, txt_ip4class, txt_rangeclass, txt_bitclass);
} catch (IllegalStateException e) {
}
}
}
};
SwingUtilities.invokeLater(doHighlight);
}
});
classW.Main contains two conditions, if zero it will set other fields based on jComboBox (txt_ip4class will be replaced), if one it should be set jComboBox choosing an option. And from that option, it should do like option zero
Full code (I export these files from Netbeans project to zip):
Succeed method which using jButton to execute
Failed method which using documentListener without jButton
Full exception stacktrace is here
or
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:1338)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:658)
at javax.swing.text.JTextComponent.setText(JTextComponent.java:1669)
at engines.ClassW.setFromCombo(ClassW.java:140)
at interfaces.Netgui$1.logUpdate(Netgui.java:63)
at interfaces.Netgui$1.insertUpdate(Netgui.java:41)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1328)
at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:884)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1663)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2882)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2929)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2845)
at java.awt.Component.processEvent(Component.java:6310)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
at java.awt.Component.dispatchEventImpl(Component.java:4760)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 19 seconds)
===============EDIT 1============
Thanks to #MarkRotteveel
And this post
This problem is fixed, but another problem is exist..
Code in the doHighlight is running in a loop.
===============EDIT 2============
Updated the code.
doHighlight no longer looping when the condition doesn't equal the regex.
but still doing loop when the condition equals.
I'm getting this exception when I run my code. Even though the code runs fine, I'm getting some exceptions on the terminal
Exception in thread "AWT-EventQueue-1" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:708)
at SR.start(SR.java:38)
at SR.mouseClicked(SR.java:212)
at java.awt.Component.processMouseEvent(Component.java:6536)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Window.processEvent(Window.java:2025)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at org.GNOME.Accessibility.AtkWrapper$5.dispatchEvent(AtkWrapper.java:700)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
What am i doing wrong??
My start() method
private void start() throws IllegalStateException {
if (HelperThread == null)
HelperThread = new Thread(this);
HelperThread.start();
}
You appear to be starting the same Thread twice, which is not allowed.
If you're looking to reuse the same thread, I would recommend creating an ExecutorService instead.
The problem is that if HelperThread is not null (it already exists) and you call HelperThread.start() is tries to start() a thread that has already started or finished it's processing. If you want to restart processing, you'll have to stop the thread first. To do this gracefully, use a while (running) { } pattern in the actual thread. Then, int the start()-method, set the flag to false, wait for the thread to die and then start a new thread:
private void start() throws IllegalStateException {
if (HelperThread != null) {
running = false;
HelperThread.join(); // wait for it to die...
}
// Start fresh...
HelperThread = new Thread(this);
HelperThread.start();
}
Also, as a side note, avoid using capital letters as the first letters for variables. It should rather be "helperThread".
When I run my test JOGL app, it says that I only have GL2 available on the thread when my system supports up to OpenGL 4.1 according to the OpenGl Extensions Viewer.
Does anyone see anything obvious why only GL2 would be supported in the thread?
I am using a mid-2015 Macbook Pro with Intel Iris and AMD Radeon R9 graphics cards.
This is the very first exercise in the book [Computer Graphics Programming in OpenGL with Java].4
Java Version: Java8
JOGL Version: 2.3.2
GlueGen Version: 2.3.2
import java.nio.*;
import javax.swing.*;
import static com.jogamp.opengl.GL4.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.common.nio.Buffers;
public class Code extends JFrame implements GLEventListener {
private GLCanvas myCanvas;
public Code() {
setTitle("Chapter 2 - program1");
setSize(600, 400);
setLocation(200, 200);
myCanvas = new GLCanvas();
myCanvas.addGLEventListener(this);
this.add(myCanvas);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void display(GLAutoDrawable drawable) {
GL4 gl = (GL4) GLContext.getCurrentGL();
drawable.setGL(new DebugGL4(gl));
float bkg[] = { 1.0f, 0.0f, 0.0f, 1.0f };
FloatBuffer bkgBuffer = Buffers.newDirectFloatBuffer(bkg);
gl.glClearBufferfv(GL_COLOR, 0, bkgBuffer);
}
public static void main(String[] args) {
new Code();
}
public void init(GLAutoDrawable drawable) {
GL4 gl = drawable.getGL().getGL4(); // This is where the code fails
String version = gl.glGetString(GL4.GL_VERSION);
String shaderversion = gl.glGetString(GL4.GL_SHADING_LANGUAGE_VERSION);
System.out.println("GLVERSION: " + version + " shading language: " + shaderversion );
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
public void dispose(GLAutoDrawable drawable) { }
}
Exception:
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -classpath /private/var/folders/rd/tltb7sk928x_n429dyctdt8c0000gn/T/classpath1.jar -Dfile.encoding=UTF-8 com.intellij.rt.execution.application.AppMain Code
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Not a GL4 implementation on thread AWT-EventQueue-0
at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1438)
at com.jogamp.opengl.Threading.invoke(Threading.java:223)
at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505)
at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:559)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
at sun.lwawt.LWRepaintArea.paintComponent(LWRepaintArea.java:59)
at sun.awt.RepaintArea.paint(RepaintArea.java:240)
at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1314)
at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1198)
at java.awt.Component.dispatchEventImpl(Component.java:4965)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: com.jogamp.opengl.GLException: Not a GL4 implementation
at jogamp.opengl.gl4.GL4bcImpl.getGL4(GL4bcImpl.java:40464)
at Code.init(Code.java:38)
at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:644)
at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:667)
at com.jogamp.opengl.awt.GLCanvas$10.run(GLCanvas.java:1407)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1291)
... 30 more
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_OPERATION ( 1282 0x502), on thread AWT-EventQueue-0
at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1438)
at com.jogamp.opengl.Threading.invoke(Threading.java:223)
at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505)
at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:559)
at com.jogamp.opengl.awt.GLCanvas.update(GLCanvas.java:866)
at sun.awt.RepaintArea.updateComponent(RepaintArea.java:255)
at sun.lwawt.LWRepaintArea.updateComponent(LWRepaintArea.java:47)
at sun.awt.RepaintArea.paint(RepaintArea.java:232)
at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1314)
at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1198)
at java.awt.Component.dispatchEventImpl(Component.java:4965)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: com.jogamp.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_OPERATION ( 1282 0x502),
at com.jogamp.opengl.DebugGL4bc.writeGLError(DebugGL4bc.java:31803)
at com.jogamp.opengl.DebugGL4bc.glActiveTexture(DebugGL4bc.java:232)
at jogamp.opengl.GLFBODrawableImpl.swapFBOImpl(GLFBODrawableImpl.java:471)
at jogamp.opengl.GLFBODrawableImpl.swapBuffersImpl(GLFBODrawableImpl.java:426)
at jogamp.opengl.GLDrawableImpl.swapBuffers(GLDrawableImpl.java:88)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1295)
... 31 more
Process finished with exit code 0
It turns out that OSX falls back to OpenGL 2.1 so you need to set the core profile yourself.
$ glxinfo | grep OpenGL
OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: AMD Radeon R9 M370X OpenGL Engine
OpenGL version string: 2.1 ATI-1.42.15
OpenGL shading language version string: 1.20
I was able to set the core version (OpenGL 4.1) by passing GLCapabilities into the GLCanvas constructor.
Here is the new, fixed constructor:
public Code() {
setTitle("Chapter 2 - program1");
setSize(600, 400);
setLocation(200, 200);
// This was the fix
GLProfile glp = GLProfile.getMaxProgrammableCore(true);
GLCapabilities caps = new GLCapabilities(glp);
myCanvas = new GLCanvas(caps);
myCanvas.addGLEventListener(this);
this.add(myCanvas);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
For running the book's examples on a Mac, I have placed instructions on this website: http://athena.ecs.csus.edu/~gordonvs/errataMac.html
In summary, you need to:
make sure you've installed the latest Java SE
place the relevant JOGL libraries into System/Library/Java/Extensions (the particular ones required are listed in the above website)
add the code described above by Julien (thanks!)
change the version numbers on the shaders to 410 (or whatever your Mac supports)
in the examples that use textures, replace the binding layout qualifiers in the shaders to appropriate calls to glUniform1i() in the Java application (for compatibility with version 4.1)
If more idiosyncrasies are identified, I'll add them to the instructions in the website.
I have created a method using JFreeChart and SQL that essentially creates a graph based on the data present in the database. I have 3 methods, one particular example, the users weight vs time. I wish to display these graphs in a JTabbedPane and am unsure how. When I call the method on the one tab it tells me static/void methods are not allowed. My method has no paramters. Here is my initial attempt:
panelWeight = new JPanel();
panelWeight.setLayout(null);
panelWeight.add(StatGraph.WeightGraph());
EDIT:
I returned to the drawing board, after discovering a) I cannot call a void method to the component and B) a null layout does not scale. Here is my re-written method I wish to call to the JTabbedPane, making the method non-void.
public static ChartFrame WeightGraph(){
ChartFrame returnFrame = null;
try{
ConnectionManager connectionManager = ConnectionManager.getInstance();
Connection connection = connectionManager.getConnection();
UserInfoManager user = new UserInfoManager();
int username = user.getId();
String query = "SELECT DATE, WEIGHT FROM STATS WHERE ID=" + username; JDBCCategoryDataset dataset = new JDBCCategoryDataset(connection, query);
JFreeChart chart = ChartFactory.createLineChart("WEIGHTvsDATE Chart", "Date", "Weight", dataset, PlotOrientation.VERTICAL, false, true, true);
BarRenderer renderer = null;
CategoryPlot plot = null;
renderer = new BarRenderer();
ChartFrame frame = new ChartFrame("Progress Log", chart);
returnFrame = frame;
//frame.setVisible(true);
//frame.setSize(750,400);
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
return returnFrame;
}
I then return to the GUI Frame and add the following code to the Panel in the TabbedPane, activated by using a click listener.
panelWeight.add(StatGraph.WeightGraph());
However, I get the following error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.checkNotAWindow(Container.java:488)
at java.awt.Container.addImpl(Container.java:1089)
at java.awt.Container.add(Container.java:415)
at GUI.PT.ProgressStatsPT.panelWeightMouseClicked(ProgressStatsPT.java:392)
at GUI.PT.ProgressStatsPT.access$600(ProgressStatsPT.java:26)
at GUI.PT.ProgressStatsPT$7.mouseClicked(ProgressStatsPT.java:138)
at java.awt.Component.processMouseEvent(Component.java:6528)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4542)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
What does exactly Graph.weightLg() return? The add() method from JPanel takes an instance of Component or a subclass. If the Graph.weightLg() method doesn't return anything (which I suppose is your case) the compilation will fail.