Hello Guest

Mac OSX - GLFW window issues

  • 5 Replies
  • 5256 Views
Mac OSX - GLFW window issues
« on: October 06, 2018, 15:38:29 »
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:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
[...] mainbasesystem.local java[384] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
GLFW window creation code is as follows:
 
Code: [Select]
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?

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: Mac OSX - GLFW window issues
« Reply #1 on: October 06, 2018, 22:13:13 »
Afaict, JavaCV has AWT dependencies and may be causing this issue.

Re: Mac OSX - GLFW window issues
« Reply #2 on: October 06, 2018, 23:27:47 »
Tried removing JavaCV entirely, even the library in itself, but the issue still remains the same.
« Last Edit: October 06, 2018, 23:29:30 by StubbyRogue46 »

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: Mac OSX - GLFW window issues
« Reply #3 on: October 06, 2018, 23:32:30 »
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?

Re: Mac OSX - GLFW window issues
« Reply #4 on: October 07, 2018, 00:47:09 »
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.
« Last Edit: October 07, 2018, 00:49:14 by StubbyRogue46 »

Re: Mac OSX - GLFW window issues
« Reply #5 on: October 07, 2018, 01:18:45 »
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.
« Last Edit: October 07, 2018, 12:51:55 by StubbyRogue46 »