LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: Obsyd on June 29, 2016, 09:55:57

Title: Window focus when files have been created
Post by: Obsyd on June 29, 2016, 09:55:57
Hello there!

My system: OS X 10.11.5 with an AMD 280X

Whenever I create a few files before I create the LWJGL window. The window will not be focused (the window shows up behind the netbeans window) and no WindowFocusCallback callbacks show up. When this happens input acts weird (for example: the mouse coords only update if I hold down the right click) and if I maximize the window (green fullscreen maximize on OSX) I get these errors:
(these errors only happen if I create files before I create the LWGL window)

Code: [Select]
Jun 29 11:50:37  java[2251] <Error>: CGWindowContextCreate: failed to create window context delegate.
Jun 29 11:50:37  java[2251] <Error>: CGWindowContextCreate: failed to create window context delegate.
Jun 29 11:50:37  java[2251] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextResetCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextResetClip: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextScaleCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: clip: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jun 29 11:50:37  java[2251] <Error>: CGContextSynchronize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

The files I create are not open. They are closed properly. During file creation I use ImageIO and simple FileOutputStream with flush and close. And they are created properly.
The same thing happens if I run my app from netbeans and from the terminal.
The logic() part of the app runs fine. I see my performance charts being updated nicely. The only problem is that the window does not seem to be focused properly.

Thank you!

Title: Re: Window focus when files have been created
Post by: Obsyd on June 29, 2016, 10:02:53
I tried to force glfwFocusWindow in my main loop. It did not help.
Title: Re: Window focus when files have been created
Post by: Obsyd on June 29, 2016, 10:17:03
While looking (profiling) at the active threads. When the problem occurs I see an additional thread called Java2D Disposer running along all other threads. When I don't create files this thread does not fire up. It probably has to do with something related to ImageIO right?
Title: Re: Window focus when files have been created
Post by: Cornix on June 29, 2016, 13:15:40
I think ImageIO is connected to the AWT. On MacOS you are not allowed to have the AWT and GLFW running simultaneously for reasons connected to the -XStartOnFirstThread stuff. I dont know if using ImageIO is enough to trigger the problems but judging from what you are describing I guess it is.
Title: Re: Window focus when files have been created
Post by: Obsyd on June 29, 2016, 13:40:59
That's what I'm thinking too. But the only thing I do is a simple ImageIO.read.
Title: Re: Window focus when files have been created
Post by: CoDi on June 29, 2016, 14:10:06
Try to call this before doing anything ImageIO:

Code: [Select]
System.setProperty("java.awt.headless", "true");
Title: Re: Window focus when files have been created
Post by: Obsyd on June 29, 2016, 14:18:32
If I specify headless GLFW throws nullpointers.

Code: [Select]
java.lang.NullPointerException
at org.lwjgl.system.Checks.checkPointer(Checks.java:103)
at org.lwjgl.glfw.GLFW.nglfwGetVideoMode(GLFW.java:1202)
at org.lwjgl.glfw.GLFW.glfwGetVideoMode(GLFW.java:1222)
Title: Re: Window focus when files have been created
Post by: CoDi on June 29, 2016, 14:39:21
Uhm, any other warnings/errors written to the terminal?

I use it the other way around. I create the window first. The file operations (custom libGDX texture packer, which re-packs some sprite atlas on demand) are done in the first "loading screen", so GLFW is initialized and the window is visible when I set awt.headless.
Title: Re: Window focus when files have been created
Post by: Obsyd on June 29, 2016, 15:05:42
Code: [Select]
Jun 29 17:05:00  java[1891] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Jun 29 17:05:00  java[1891] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Jun 29 17:05:00  java[1891] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Title: Re: Window focus when files have been created
Post by: Cornix on June 29, 2016, 15:22:37
I guess a simple example program would be useful to find out what the problem is.
Title: Re: Window focus when files have been created
Post by: spasi on June 29, 2016, 15:30:24
LWJGL comes with stb bindings, which includes stb_image for reading images and stb_image_write for writing them. They can be used to replace ImageIO, removing the AWT dependency. Using awt.headless on MacOS may work, but it is not guaranteed and not supported by LWJGL in any way.
Title: Re: Window focus when files have been created
Post by: Obsyd on June 30, 2016, 06:22:54
Sadly I would really like to use ImageIO. I will further investigate the problem to see if maybe it is caused by something else I'm doing. Thank you for the replies guys!
Title: Re: Window focus when files have been created
Post by: Obsyd on July 24, 2016, 09:33:14
Anyone else having problems extracting the latest nightlies?
Title: Re: Window focus when files have been created
Post by: spasi on July 24, 2016, 11:44:34
I just tried the latest nightly build (3.0.1 #10) without any issues. What kind of problems are you having?
Title: Re: Window focus when files have been created
Post by: Obsyd on July 24, 2016, 12:40:34
When I download the latest build the zip is 27MB (used to be less). After I extract it I get a lot of jars and folders.
Title: Re: Window focus when files have been created
Post by: spasi on July 24, 2016, 13:22:01
See issue #100 (https://github.com/LWJGL/lwjgl3/issues/100). Note that we're currently working on:

a) Maven artifacts.
b) A tool on the website that generates Maven/Gradle scripts and IDE projects.
c) A tool on the website that lets you customize the downloaded .zip.
Title: Re: Window focus when files have been created
Post by: Nazerak on August 16, 2016, 01:11:40
I just tried the latest nightly build (3.0.1 #10) without any issues. What kind of problems are you having?

The way you add LWJGL to Eclipse (for example) has changed with what appears to be your modular approach in the nightly builds.  Previously I only had to add lwjgl.jar as an external JAR and point the IDE to the /natives/ folder and to src.zip for everything to work smoothly.  With your newer approach I am unsure how to add what I need to Eclipse and how to point the options to the correct locations and/or files in order for everything to work as it did before.
Title: Re: Window focus when files have been created
Post by: spasi on August 16, 2016, 09:17:35
The new structure is similar:

- Each module has at least 3 JARs: the classes (no suffix), the sources (-sources) and the javadoc (-javadoc).
- Some modules also include native library JARs (with a -natives-<arch> suffix).
- You only need the class and native library JARs in your classpath. The others may be "attached" to your IDE project for quick source/javadoc lookups.

LWJGL automatically extracts native libraries from the classpath, so you normally don't need to set -Djava.library.path. If you prefer the old way, you may extract the native library JARs to a folder and use that instead.

You always need the "core" module (i.e. lwjgl.jar and lwjgl-natives-<arch>.jar) in your project. Then you add any bindings that you want to use and ignore the rest. All binding modules depend on the core module, but there are no other dependencies.
Title: Re: Window focus when files have been created
Post by: Obsyd on August 27, 2016, 09:58:49
This new modular system is really great. Makes things cleaner and smaller. Thanks Spasi!