Solved: Nifty.update after swing JFrame leads to error

Hello, I want to use some simple swing JFrame windows for editing settings. But when I close the JFrame and want to continue with the JME part of the programm I get the following error. It happens in the moment I call “nifty.update” (nifty is "public static Nifty nifty; in my main). Does anyone have any idea what the problem could be.

Exception in thread “AWT-EventQueue-0” java.lang.RuntimeException: No OpenGL context found in the current thread.
windowListener windowDeactivated e.toString = java.awt.event.WindowEvent[WINDOW_DEACTIVATED,opposite=null,oldState=0,newState=0] on frame0
windowListener windowClosed e.toString = java.awt.event.WindowEvent[WINDOW_CLOSED,opposite=null,oldState=0,newState=0] on frame0
Main.endActiveCommand() Step1
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
Main.endActiveCommand() Step2
at org.lwjgl.opengl.GL11.glBindTexture(GL11.java:651)
at com.jme3.renderer.lwjgl.LwjglGL.glBindTexture(LwjglGL.java:54)
main.goToActiveDialog() GESTARTET / activeDialog = TOOLBOX_STANDARD
at com.jme3.renderer.opengl.GLRenderer.bindTextureAndUnit(GLRenderer.java:2356)
at com.jme3.renderer.opengl.GLRenderer.updateTexImageData(GLRenderer.java:2409)
at com.jme3.renderer.opengl.GLRenderer.setTexture(GLRenderer.java:2545)
at com.jme3.renderer.opengl.GLRenderer.modifyTexture(GLRenderer.java:2560)
at com.jme3.niftygui.JmeBatchRenderBackend.modifyTexture(JmeBatchRenderBackend.java:361)
at com.jme3.niftygui.JmeBatchRenderBackend.access$300(JmeBatchRenderBackend.java:75)
at com.jme3.niftygui.JmeBatchRenderBackend$ImageImpl.modifyTexture(JmeBatchRenderBackend.java:392)
at com.jme3.niftygui.JmeBatchRenderBackend.addImageToAtlas(JmeBatchRenderBackend.java:228)
at de.lessvoid.nifty.render.batch.BatchRenderImage.uploadImageToAtlas(BatchRenderImage.java:197)
at de.lessvoid.nifty.render.batch.BatchRenderImage.upload(BatchRenderImage.java:142)
at de.lessvoid.nifty.render.NiftyImageManagerExtBatch$ReferencedCountedImageBatch.upload(NiftyImageManagerExtBatch.java:169)
at de.lessvoid.nifty.render.NiftyImageManagerExtBatch.uploadScreenImages(NiftyImageManagerExtBatch.java:69)
at de.lessvoid.nifty.render.NiftyImageManager.uploadScreenImages(NiftyImageManager.java:60)
at de.lessvoid.nifty.render.NiftyRenderEngineImpl.screenStarted(NiftyRenderEngineImpl.java:900)
at de.lessvoid.nifty.screen.Screen.startScreen(Screen.java:216)
at de.lessvoid.nifty.Nifty.gotoScreenInternal(Nifty.java:767)
at de.lessvoid.nifty.Nifty.access$400(Nifty.java:87)
at de.lessvoid.nifty.Nifty$1.perform(Nifty.java:724)
at de.lessvoid.nifty.elements.EndOfFrameElementAction.perform(EndOfFrameElementAction.java:24)
at de.lessvoid.nifty.Nifty.executeEndOfFrameElementActionsInternal(Nifty.java:490)
at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:442)
at de.lessvoid.nifty.Nifty.update(Nifty.java:373)
at mygame.Main.goToActiveDialog(Main.java:464)
at mygame.Main.endActiveCommand(Main.java:779)
at mygame.SeitenteileAendern$2.windowClosed(SeitenteileAendern.java:276)
at java.desktop/java.awt.Window.processWindowEvent(Window.java:2081)
at java.desktop/javax.swing.JFrame.processWindowEvent(JFrame.java:298)
at java.desktop/java.awt.Window.processEvent(Window.java:2037)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5008)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
AL lib: (EE) alc_cleanup: 1 device not closed

You can only call those update methods (not only Nifty’s) on the jME render thread. Now you are maybe calling it from a Swing thread (looks like that from the stack)? I think you are using LWJGL 2 from the stack, at least with LWJGL 3 this stunt won’t be possible at all.

But if I’m correct, just enqueue the nifty.update() to the app.enqueue queue to be executed on the render thread.

1 Like

Thank you very much. I solved ist with this now in the windowListener:

Main.app.enqueue(
    new Runnable() {
    @Override
        public void run() {
            Main.endActiveCommand();
        }
    }
);
1 Like