Why I'm stuck on 2.9.3

Started by MrkBoston2, June 16, 2019, 22:09:41

Previous topic - Next topic

MrkBoston2

I've been writing software using the LWJGL libraries since around 2013. A few years back, I wanted to upgrade the libraries to use the latest 3.x version.  I spent several days swapping out libraries and converting my code to use GLFW windowing. Eventually, nothing would work, so I gave up and switched to the most recenter version of LWJGL2, which was version 2.9.3. I've been stuck here for years.

If you had asked me at the time if I'd recommend LWJGL v3 to a friend, I'd say "Absolutely not!" Why? Well, I don't want my friends to hate me.

A few days ago, I had some extra vacation time, and decided to give LWJGL3 one more try. Surely, most of the early transition phase issues have been resolved, and hopefully the documentation makes it easier to integrate the libraries. But this time, I'd avoid the pain of converting a large existing program, and would instead try working from the ground up. Let's try the basic tutorial and get the libraries to do something... anything... How hard could it be?

I downloaded the stable release version (3.2.2) and started to do a Grade build using Eclipse as the IDE. The documentation make it sound easy to set up a <lwjgl3> library, but with nearly 37 separate libraries, doing that without error is a daunting task. After a couple of fruitless wasted hours, I decided to hand configure a build space. To minimize issues, I elected to get the simple HelloWorld program running without the use of Grade. I'd also use a shell script to ensure that the library setup was simple and correct for both the class path and load libraries.

The first program is the one posted on the 'Get Started' tab.  Hey, I've been writing OpenGL code since the '90s, so this simple example should help wring out issues setting up libraries. Alas, no such luck. Hour after hour was spent trying to isolate why a built program wouldn't compile or execute. I remember first learning OpenGL on C/C++, and it was an outright breeze compared to this. I've even considered that it might be easier to just switch languages, at least my code would run faster.

So here I am on day two. I started keeping a journal of all the problems that I ran into and the eventual solutions. Each program solved caused yet-another to be revealed. I've cracked open jar files, scrubbed through .dylibs and done a ton of other work to diagnose where things have gone wrong.

Version 3 has way too many libraries. Version 2.x had a half dozen or so, but dealing with 37 is a bit extreme.  I believe that the following set should get the demo code working:

lwjgl, assume, bgfx, glow, nanovg, nuklear, obenan, OpenGL, par, stb and Vulcan.

So here's my 'simple' script:

---------
#!/bin/csh

echo "***** Running HelloWorld w/LWJGL-3.2 *****"
echo " "
echo "[Executing Demo HelloWorld]"
echo " "

setenv LD_LIBRARY_PATH /proj/TestGL3/lib/lwjgl-3.2
setenv DYLD_LIBRARY_PATH /proj/TestGL3/lib/lwjgl-3.2

/usr/bin/java -Xmx1024m -showversion -Djava.library.path="/proj/TestGL/lib/lwjgl-3.2/native/macosx" -cp ../build/classes/java/main:../lib/lwjgl-3.2/lwjgl.jar:../lib/lwjgl-3.2/lwjgl-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-assimp.jar:../lib/lwjgl-3.2/lwjgl-assimp-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-bgfx.jar:../lib/lwjgl-3.2/lwjgl-bgfx-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-glfw.jar:../lib/lwjgl-3.2/lwjgl-glfw-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-nanovg.jar:../lib/lwjgl-3.2/lwjgl-nanovg-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-nuklear.jar:../lib/lwjgl-3.2/lwjgl-nuklear-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-openal.jar:../lib/lwjgl-3.2/lwjgl-openal-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-opengl.jar:../lib/lwjgl-3.2/lwjgl-opengl-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-par.jar:../lib/lwjgl-3.2/lwjgl-par-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-stb.jar:../lib/lwjgl-3.2/lwjgl-stb-natives-macos.jar:../lib/lwjgl-3.2/lwjgl-vulcan.jar:../lib/lwjgl-3.2/lwjgl-vulcan-natives-macos.jar gdemo.HelloWorld
------- EOF------

After spending nearly 16 hours to get to this point, it doesn't work. Here's my current error:


------------
***** Running HelloWorld w/LWJGL-3.2 *****

[Executing Demo HelloWorld]

java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Hello LWJGL 3.2.2 build 10!
2019-06-16 17:46:43.250 java[1364:99471] WARNING: nextEventMatchingMask should only be called from the Main Thread! This will throw an exception in the future.
2019-06-16 17:46:43.250 java[1364:99471] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1349.92/Misc.subproj/NSUndoManager.m:363
2019-06-16 17:46:43.251 java[1364:99471] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1349.92/Misc.subproj/NSUndoManager.m:363
2019-06-16 17:46:43.252 java[1364:99471] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
   0   CoreFoundation                      0x00007fff8cff994b __exceptionPreprocess + 171
   1   libobjc.A.dylib                     0x00007fffa23f11da objc_exception_throw + 48
   2   CoreFoundation                      0x00007fff8cffe502 +[NSException raise:format:arguments:] + 98
   3   Foundation                          0x00007fff8ea65a00 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
   4   Foundation                          0x00007fff8e9efeb3 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 170
   5   AppKit                              0x00007fff8aa584ed -[NSApplication run] + 1200
   6   libglfw.dylib                       0x00000001262279d5 libglfw.dylib + 68053
   7   libglfw.dylib                       0x0000000126221366 libglfw.dylib + 41830
   8   ???                                 0x00000001123b5ad0 0x0 + 4600847056
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort
------------

OK, this last ditch attempt at getting LWJGL3 to run has turned into a bust. Lots of time was spent documenting issues with library internals and loading errors.  I've wasted an entire long weekend with not even a single polygon or window display to show for it.

If the code had ever started to work, I was planning on uploading the entire folder for others to try. Perhaps a simple working example, even of the most basic form, would be useful in diagnosing issues and ensuring that the libraries could even do the most basic of tasks.

It looks like I'm back to 2.9.3. Stuck again.  Maybe 3.3.x  or 4.x will be better.  Maybe next year will bring better luck.

Tomorrow is another day, and you never know that the tide may bring. ;)









kappa

Yeh, there are a lot of jars, however most will not need need to use them all.

Personally, if using eclipse and wanting to run a simple first test, i'd do the following:

1) Go to the LWJGL customize download page.
2) Grab the 'Minimal OpenGL' zip bundle (untick the source and javadoc jars to reduce number of jars).
3) Create a new eclipse project and add all the jars to the build path (in LWJGL3 you don't need to extract the natives from the jars like with LWJGL2).
4) If on mac, you must set the VM argument -XstartOnFirstThread
5) The sample code from https://www.lwjgl.org/guide should now just work (you shouldn't have to do more than the above to get it to work).

Hope that helps.

spasi

I'm sorry to hear about your experience, but it sounds like you tried random solutions without doing any research. I'm not suggesting anything difficult, LWJGL doesn't exist in a void, there's the website, the source in the github repository, README files, open & closed issues, the forum, javadoc. Actually, the amount of documentation in LWJGL is ridiculous, there's so much more documentation than code.

Or you could simply have asked before wasting time. That's why we have the forum, the Slack team, the Twitter account.

So, here are some simple instructions for running the HelloWorld sample code:

1. Go to https://www.lwjgl.org/customize and download LWJGL. You don't need "37 libraries", you need just 3: core, GLFW, OpenGL.
2. Extract the downloaded .zip file to a folder
3. Create HelloWorld.java and copy the code.

(using the folder structure from your post)

4. javac -cp ../lib/lwjgl-3.2/* gdemo/HelloWorld.java
5. java -cp .:../lib/lwjgl-3.2/* -XstartOnMainThread gdemo.HelloWorld

You don't need a million jars, you don't have to list them one-by-one, you don't have to mess with the library path. A lot of effort has been spent on making this possible and I don't know what could possibly be simpler than the above, given what LWJGL is and what it does.

A few more comments, so that you don't waste more time:

- Eclipse has trouble with Java modules. Every user that has tried to use LWJGL as modules with Eclipse has failed. This is not a problem with LWJGL, which is correctly configured as explicit modules and works fine in every other IDE or cli environment. As a workaround, ignoring modules and putting LWJGL in the classpath will work fine.
- GLFW requires that most of its functions are called from the main thread. On macOS, that thread must also be the first thread in the process (that's why -XstartOnMainThread is needed). This is not a problem with LWJGL and not a problem with GLFW, it's how macOS works.
- When getting started, it's highly recommended to use https://github.com/LWJGLX/debug. If you're doing something obviously wrong, it will tell you immediately.

localhost

I'm finishing off a port from 2.9.3 to 3.2.2 because 2.9.3 is completely dead for me (Ubuntu J11).
The event handling and startup code were major work, but fairly painless.  Oh, I did lose fullscreen mode and mouse capture, which I haven't figured out.
The loss of Slick was problematic; rewriting the texture handling was easy but the bulk of my time was spent figuring out font handling. Bleh.

Just getting all the jars bootstrapped was an adventure.  Normally, I like to maven/gradle everything from mvnrepository.com. However, the natives aren't up there, they require downloading and manually dropping in, so why not just download all of lwjgl to ensure matched versions.
I think the eclipse page could use some updating.  What works for me is to create a ${projectroot}/lwjgl directory and put the 27 jars I want in there.
Then I created an LWJGL user library with the build/runtime jars in there.  Then I could attach the *-sources.jar to each jar to get useful development info out of lwjgl.

A lot of the tutorials are based on 2.9.x, including the front lwjgl wiki page, so that can be confusing and not helpful.

Spasi wrote:
> 1. Go to https://www.lwjgl.org/customize and download LWJGL. You don't need "37 libraries", you need just 3: core, GLFW, OpenGL.

It's a bit more than that, isn't it?  You also need the -natives-os.jar(s) to go with the "just 3", yes?

So I have my game running.  Under 3.2.2 it is a *lot* less smooth than 2.9.3.  I'm just starting to look at that.

My mantra, with things that I can't make work like fullscreen/mouse capture, is, "Minecraft does it and that is way more complicated than what I'm doing". (I think GLUT is my answer to this problem).


spasi

Quote from: localhost on June 17, 2019, 08:46:23Normally, I like to maven/gradle everything from mvnrepository.com. However, the natives aren't up there, they require downloading and manually dropping in, so why not just download all of lwjgl to ensure matched versions.

That's wrong, the natives are available on Maven Central. LWJGL uses classifiers (just like -javadoc and -sources) for the native artifacts, for example these are the GLFW artifacts for 3.2.2: https://repo1.maven.org/maven2/org/lwjgl/lwjgl-glfw/3.2.2/

The build customizer on the LWJGL website can generate appropriate Maven/Gradle scripts for you. You don't have to manually download anything (for development at least).

Quote from: localhost on June 17, 2019, 08:46:23It's a bit more than that, isn't it?  You also need the -natives-os.jar(s) to go with the "just 3", yes?

My point is you simply need to choose the bindings you're interested in. You get all necessary files in a single .zip file, you extract it and are ready to go. There are more files in there anyway (licenses, sources, javadoc, etc.).

localhost

1) I didn't mean to hijack OP's thread.
2) When I set pen to paper, my intent was to encourage OP to finish the transition. "It's worth it.  Yay rah rah!" It didn't come out that way.

3)
Spasi wrote:
> these are the GLFW artifacts for 3.2.2: https://repo1.maven.org/maven2/org/lwjgl/lwjgl-glfw/3.2.2/
I see the natives there.  Weird that I don't see them here: https://mvnrepository.com/search?q=lwjgl-glfw
and when I tried manually manually specifying them, they didn't get found. (I have a private nexus server which mirrors <url>https://repo1.maven.org/maven2/</url>)
That _does not matter_ at all, because in eclipse, one cannot attach source/javadoc to an "External jar or dependency" anyways.  It is much better to just fetch the zip and include the lwjgl jars in my project so I can attach source, so I can see what's what.

4) I finished my upgrade from 2.9.3 to 3.2.2.  Interesting that it's different.  I would think the underlying opengl library would be the same, and it would be the same. 
On one machine (GTX 1080) the color transitions, and fades are subtle and just brilliant and runs a solid 60 fps.
My dev box, (i7 with onboard GT 625) is not a game machine.  But it plays videos at 1920x1200 just fine and Minecraft runs at 30-22 fps. Acceptable for what it is.
My game however, with 2.9.3 runs at 60 fps slowing to 40 with decent busyness on the screen.  Acceptable.  But 3.2.2 quickly drops to  20 fps, (which I think is optimistic ;)), and playing against humans becomes impossible.  I guess if I'm going to continue this game stuff I need a new power supply.

KaiHH

> I see the natives there.  Weird that I don't see them here: https://mvnrepository.com/search?q=lwjgl-glfw

It's the same reason that you don't see the javadoc and sources jars there. The web interface of repo1.maven.org simply only displays the artifacts with classifier 'jar' (the default) and not any other classifier, such as javadoc, sources or natives-<OS>.

> in eclipse, one cannot attach source/javadoc to an "External jar or dependency" anyways
If by that you mean Library dependencies (such as the "Maven Dependencies" library automatically added by Eclipse when importing a Maven project) then this simply is not true. Maven will attach the sources and javadoc jars automatically. See https://i.imgur.com/NVmXvtz.png for a view of my Eclipse build settings of the lwjgl3-demos repository https://github.com/LWJGL/lwjgl3-demos which was fully automatically set up in Eclipse when choosing Import Maven Project in Eclipse, with sources and javadocs attached completely automatically. You do not have to do ANYTHING (such as downloading zips, jars or anything) manually.
All you need to do is go to lwjgl.org/customize and select Maven and the artifacts you need and paste the resulting pom.xml snippet into your pom.xml.

There simply is no easier way to setup an LWJGL3 project than to use Maven/Gradle. Literally!
Probably hundreds of people have managed to setup LWJGL3 in their Maven project, and so can you! :)

MrkBoston2

It's been a while since I last tried to get LWJGL 3 to work, and since my platform has upgraded, it seemed like it would be worth another try. The machine has been upgraded to OSX Mojave, and a new Radeon RX580 is doing the heavy lifting.

I thought I'd dispense with Eclipse and just try the 'simple' manual steps listed below:

1. Go to https://www.lwjgl.org/customize and download LWJGL. You don't need "37 libraries", you need just 3: core, GLFW, OpenGL.
2. Extract the downloaded .zip file to a folder
3. Create HelloWorld.java and copy the code.

(using the folder structure from your post)

4. javac -cp ../lib/lwjgl-3.2/* gdemo/HelloWorld.java
5. java -cp .:../lib/lwjgl-3.2/* -XstartOnMainThread gdemo.HelloWorld

------------
OK, bottom line up front:It didn't work at all!

Running the compile command (#4) results in command line errors:
javac -cp ../lib/*.jar gdemo/HelloWorld.java
error: invalid flag: ../lib/lwjgl-glfw.jar

Usage: javac <options> <source files>
use --help for a list of possible options

To get around that, the command was extended to list all of the relevant .jar files in the class path statement:

javac -cp "../lib/lwjgl-assimp.jar:../lib/lwjgl-bgfx.jar:../lib/lwjgl-glfw.jar:../lib/lwjgl-nanovg.jar:../lib/lwjgl-nuklear.jar:../lib/lwjgl-openal.jar:../lib/lwjgl-opengl.jar:../lib/lwjgl-par.jar:../lib/lwjgl-stb.jar:../lib/lwjgl-vulcan.jar:../lib/lwjgl.jar" gdemo/HelloWorld.java

OK, it compiles!!!!!  Now let's run it.

java -cp "../lib/lwjgl-assimp.jar:../lib/lwjgl-bgfx.jar:../lib/lwjgl-glfw.jar:../lib/lwjgl-nanovg.jar:../lib/lwjgl-nuklear.jar:../lib/lwjgl-openal.jar:../lib/lwjgl-opengl.jar:../lib/lwjgl-par.jar:../lib/lwjgl-stb.jar:../lib/lwjgl-vulcan.jar:../lib/lwjgl.jar" -XstartOnMainThread gdemo.HelloWorld
Unrecognized option: -XstartOnMainThread

OK. it looks like the -XstartOnMainThread flag doesn't exist anymore. Hmm... let's try it again without the flag and and with some additional diagnostics. The 'gdemo' package was removed and a print of "HelloWorld" was injected before the actual LWJGL startup, just to make sure the program was actually found and starting. OK, recompile... check!

Here goes the execution:

java -showversion -cp ".:../lib/*" HelloWorld
java version "13.0.1" 2019-10-15
Java(TM) SE Runtime Environment (build 13.0.1+9)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
HelloWorld
Hello LWJGL 3.2.3 build 13!
2020-02-28 18:14:25.852 java[4082:206397] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1575.22/Foundation/Misc.subproj/NSUndoManager.m:361
2020-02-28 18:14:25.852 java[4082:206397] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
   0   CoreFoundation                      0x00007fff5397ba7d __exceptionPreprocess + 256
   1   libobjc.A.dylib                     0x00007fff7e071a17 objc_exception_throw + 48
   2   CoreFoundation                      0x00007fff53996796 +[NSException raise:format:arguments:] + 98
   3   Foundation                          0x00007fff55c36791 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
   4   Foundation                          0x00007fff55b6980e +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 473
   5   AppKit                              0x00007fff50eb4661 -[NSApplication run] + 916
   6   libglfw.dylib                       0x000000011165ba85 libglfw.dylib + 68229
   7   libglfw.dylib                       0x0000000111655416 libglfw.dylib + 42006
   8   ???                                 0x00000001126fcc90 0x0 + 4604284048
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Hmmm... sounds like we really need to start on the right thread with LWJGL. Does anyone actually run LWJGL3 on OSX?

KaiHH

Quote from: MrkBoston2 on February 28, 2020, 23:23:37
Unrecognized option: -XstartOnMainThread

OK. it looks like the -XstartOnMainThread flag doesn't exist anymore
It has never been "-XstartOnMainThread". It has always been "-XstartOnFirstThread".
After having seen "Unrecognized option: -XstartOnMainThread" I would've immediately copy&pasted "-XstartOnMainThread" into Google and this would have yielded: "Did you mean '-XstartOnFirstThread'" right at the top.

MrkBoston2

Thanks! That did the trick. I'm finally seeing the red display window.

I did search on DuckDuckGo for the term "-XstartOnMainThread". In the list of responses I just didn't notice that the flag name had been corrected to "-XstartOnFirstThread."

Thanks again for the fast help. Maybe now I can finally make the big transition  ;)