Hello Guest

Lwjgl3 doesn't like java.awt.Color? [MACOS]

  • 8 Replies
  • 3780 Views
Lwjgl3 doesn't like java.awt.Color? [MACOS]
« on: November 23, 2015, 04:48:21 »
So... I've been sitting here scratching my head at this one.

I started this little 3d rendering demo on my apple machine a couple of months ago. I normally only develop on it when I'm away from my desktop. Everything worked fine... I transferred all the files over to my desktop, and continued working.

I'm home from uni for Thanksgiving break, and as such I'm away from my desktop. So, I wanted to continue to develop my 3d engine. I put all the files on my machine, added that gay -XstartOnFirstThread run configuration, and pressed run. The game loaded, but no window displayed. Now, I thought this was quite odd, and so I quickly began googling for answers; nothing.

I spent hours disecting my code to see what the problem could be, but I never got any step closer. It seemed the window just didn't want to create, even though there were no errors.

Today when I was trying to copy some code over line-at-a-time, I noticed something quite odd. Referencing java.awt's Color class causes lwjgl3 to... well... break. Even if I don't use the color. JUST referencing it breaks lwjgl.

I thought I was going crazy, so I tried a simple example. I used this: Clickity Clack

It ran perfectly.

before the while loop I put:
Code: [Select]
Color unusedColor = Color.WHITE;
The window no longer loads. I'm about to cry.

I am on lwjgl3 3.0.0b
« Last Edit: November 23, 2015, 04:53:59 by orange451 »

*

Kai

Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #1 on: November 23, 2015, 08:28:42 »
Simply put: AWT does not work together with GLFW.
AWT is trying to steal the "main" thread for processing window messages when it initializes. And referencing a field inside of java.awt.Color also causes AWT to initialize, since the colors are no compiletime constants, which causes the static initializer to call Toolkit.loadLibraries().
So, you cannot use AWT and GLFW together.

*

Offline Cornix

  • *****
  • 487
Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #2 on: November 23, 2015, 09:26:45 »
Note that this will only happen on MacOS. Windows and Linux operating systems do not force GLFW or AWT to be run on the first thread.

Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #3 on: November 23, 2015, 14:33:10 »
That's awful :/

*

Kai

Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #4 on: November 23, 2015, 14:40:42 »
It's not that bad. Actually, you likely don't need AWT when using LWJGL3/GLFW.
For image I/O, for example, there is support for stb in LWJGL3.
If you need widget support, you can also use SWT, which is a lot more lightweight than AWT and also works with GLFW (though you don't need that also, since SWT will create the windows and the GL context).
Maybe you can tell a bit more why exactly you need AWT.

Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #5 on: November 23, 2015, 14:54:31 »
I only used it for the Color class ;)

Oh and image loading. I forgot that used awt too. Hah.
« Last Edit: November 23, 2015, 14:57:10 by orange451 »

*

Offline Cornix

  • *****
  • 487
Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #6 on: November 23, 2015, 16:00:34 »
If you really need the AWT Color class and you dont want to roll your own or use an existing one from the internet then you can simply copy the source code from AWT into a custom class of yours. The source code for most of the JDK is publicly available. Of course you would need to remove anything that depends on other AWT classes.

*

Offline kappa

  • *****
  • 1313
Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #7 on: November 23, 2015, 16:04:33 »
If you are not creating any AWT windows, then on OS X you can use LWJGL3 with AWT when running AWT in headless mode.

I was using AWT for font loading and it worked fine (although have switched to STB since) so should work fine for using the Color class.

As for image loading using AWT it may or may not work but give it a try. STB does provide pretty good image loading support so might be worth switching if it doesn't work.

Use the following VM arguments:

Code: [Select]
-XstartOnFirstThread -Djava.awt.headless=true
« Last Edit: November 23, 2015, 16:36:40 by kappa »

Re: Lwjgl3 doesn't like java.awt.Color? [MACOS]
« Reply #8 on: November 25, 2015, 07:15:31 »
Thank you guys for all your help ^^
My engine now works on mac!
« Last Edit: November 25, 2015, 19:26:43 by orange451 »