Mac OSX - GLFW window issues

Started by StubbyRogue46, October 06, 2018, 15:38:29

Previous topic - Next topic

StubbyRogue46

I have largely one major issue regarding GLFW window creation using LWJGL on Mac OSX. The jar-file is launched from the terminal using the following command:

java -XstartOnFirstThread -jar MyJar.jar


The problem is that the GLFW window appears behind the terminal window and is out of focus, even if you click on it. The graphics and audio of the window works perfectly (when the window is resized, for the graphics), but due to the GLFW window not being in focus no key-input can be registered. The key-input is instead being registered in the terminal window and key-input is rather important for my program.

A common answer floating around on especially the lwjgl forum is that AWT causes this issue. I have now ensured that no AWT object nor call what so ever exists in my code, but the issue remains the same. The standard active threads are the following:

main
Java Sound Event Dispatcher
MUSIC#assets/audio/music/menu.ogg


where "main" is the java main thread, "Java Sound Event Dispatcher" is probably something that has to do with javax.sound.sampled and "MUSIC#assets/audio/music/menu.ogg" is just a thread that reads data into jorbis where I have ensured that my code contains no references to anything in the AWT package. So it does not appear to exist any AWT-thread.

I have also tried both glfwWindowHint(GLFW_FOCUSED, GL_TRUE) and glfwFocusWindow(...), none of which works. I have also tried to add -Djava.awt.headless=true which just causes the terminal to output:

[...] mainbasesystem.local java[384] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.


GLFW window creation code is as follows:
public static boolean initGLFW(boolean full) {
	try{
		glfwInit();
		glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
		glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
		glfwWindowHint(GLFW_FOCUSED, GL_TRUE);
			
		try{glfwDestroyWindow(window);} catch(Exception e){}
		videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
		
		window = glfwCreateWindow(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, TITLE, 0, 0);
		glfwSetWindowPos(window, (videoMode.width()-VIEWPORT_WIDTH)/2, (videoMode.height()-VIEWPORT_HEIGHT)/2);
			
		keyHandler = new KeyHandler();
		glfwSetKeyCallback(window, keyHandler);
		glfwSetWindowSizeCallback(window, windowSize);
		glfwSetWindowIconifyCallback(window, windowIconification);
		glfwSetInputMode(window, GLFW_CURSOR, (Options.cursorBound ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL));
			
		try {
			File icon16Path = new File("assets/icon16.png");
			if(icon16Path.exists())
				glfwSetWindowIcon(window, LWJGLFunc.createGLFWIcon("assets/icon16.png", "assets/icon32.png"));
		} catch(Exception e) {
			e.printStackTrace(Core.err);
		}
			
		glfwSwapInterval(0);
		glfwMakeContextCurrent(window);
		glfwShowWindow(window);
		glfwFocusWindow(window);
		return true;
	} catch(Exception e){
		e.printStackTrace(Core.err);
	}
	return false;
}


Everything works perfectly on Windows 7 and 8.1 (where Windows 8.1 is used on the same computer as Mac OSX).

Additional info:
- Mac OSX Yosemite 10.10.5
- LWJGL 3.2.0 (custom download with GLFW and STB)
- Also javacv and jorbis

How should this problem be solved?

spasi

Afaict, JavaCV has AWT dependencies and may be causing this issue.

StubbyRogue46

Tried removing JavaCV entirely, even the library in itself, but the issue still remains the same.

spasi

Try registering a GLFWErrorCallback, or running the application with LWJGLX/debug. Also, does the bug go away if you don't do anything with jorbis and/or javax.sound.sampled?

StubbyRogue46

I have now created a test with only GLFW window creation and a simple OpenGL draw. It works.
I tried adding a javax.sampled SourceDataLine playing a wav file to the test. It works.
I tried adding some references to jorbis files and methods (not all the same from the other program). It still works.
I went through all jorbis files on their github page and found no awt imports.

I tried removing all but the GLFW window creation from the main method and startup procedure of my main program. The issue remains.
I added a GLFWErrorCallback.createPrint() with glfwSetErrorCallback(). No recorded error.
I tried removing jorbis from the class-path entirely. The issue remains.

StubbyRogue46

I have now found the source of the problem. Apparently I had missed one import of java.awt.Point in one remote class that was not even being used. So with that import removed it now works perfectly, even with both jorbis and JavaCV.

Thank you for your help and thank eclipse for the search tool.