Skip to content

Conversation

@wfouche
Copy link
Contributor

@wfouche wfouche commented Aug 17, 2025

$ jbang run Pong.java

image

//DEPS org.lwjgl:lwjgl:3.3.3
//DEPS org.lwjgl:lwjgl-glfw:3.3.3
//DEPS org.lwjgl:lwjgl-opengl:3.3.3
//DEPS org.lwjgl:lwjgl:3.3.3:natives-windows
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure that kind of deps resolution does what you hope for...only one of org.lwjgl:* artifacts will get included...first one wins.

I think that explains why I get :

jbang examples/game/Pong.java 
[jbang] Resolving dependencies...
[jbang]    org.lwjgl:lwjgl:3.3.3
[jbang]    org.lwjgl:lwjgl-glfw:3.3.3
[jbang]    org.lwjgl:lwjgl-opengl:3.3.3
[jbang] Dependencies resolved
[jbang] Building jar for Pong.java...
[LWJGL] Platform/architecture mismatch detected for module: org.lwjgl
        JVM platform:           macOS aarch64 21.0.7
                OpenJDK 64-Bit Server VM v21.0.7+6-LTS by Eclipse Adoptium
        Platforms available on classpath:
                windows/x64
                linux/x64
                macos/x64
[LWJGL] Failed to load a library. Possible solutions:
        a) Add the directory that contains the shared library to -Djava.library.path or -Dorg.lwjgl.librarypath.
        b) Add the JAR that contains the shared library to the classpath.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
[LWJGL] Enable the SharedLibraryLoader debug mode with -Dorg.lwjgl.util.DebugLoader=true for better diagnostics.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: liblwjgl.dylib
        at org.lwjgl.system.Library.loadSystem(Library.java:174)
        at org.lwjgl.system.Library.loadSystem(Library.java:64)
        at org.lwjgl.system.Library.<clinit>(Library.java:52)
        at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:100)
        at org.lwjgl.system.Pointer$Default.<clinit>(Pointer.java:67)
        at org.lwjgl.system.Callback.<clinit>(Callback.java:40)
        at Pong.init(Pong.java:79)
        at Pong.run(Pong.java:64)
        at Pong.main(Pong.java:280)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're running on macOS aarch64 which is not currently supported by the Pong.java program.

Platforms available via the classpath as reported by the runtime are:

  • windows/x64
  • linux/x64
  • macos/x64

I'll check if a native library for aarch64 is available.

@maxandersen
Copy link
Collaborator

love it - did you make the game or copied from somewhere? should make ref if from somewhere else.

we'll need to figure out how to do the deps in a portable way.

@wfouche
Copy link
Contributor Author

wfouche commented Aug 19, 2025

This game was developed from scratch using Google Gemini AI.

I tested the game on Linux and Windows, had to a make a small timing change so that Linux was properly supported.

@wfouche
Copy link
Contributor Author

wfouche commented Aug 19, 2025

we'll need to figure out how to do the deps in a portable way.

It should work now on macOS (arm64) as well.

@maxandersen
Copy link
Collaborator

i gets further but errors with:

jbang examples/game/Pong.java 
[jbang] Resolving dependencies...
[jbang]    org.lwjgl:lwjgl:3.3.6
[jbang]    org.lwjgl:lwjgl-glfw:3.3.6
[jbang]    org.lwjgl:lwjgl-opengl:3.3.6
[jbang] Dependencies resolved
[jbang] Building jar for Pong.java...
Exception in thread "main" java.lang.IllegalStateException: GLFW may only be used on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. This check may be disabled with Configuration.GLFW_CHECK_THREAD0.
	at org.lwjgl.glfw.EventLoop.check(EventLoop.java:33)
	at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1108)
	at Pong.init(Pong.java:100)
	at Pong.run(Pong.java:82)
	at Pong.main(Pong.java:298) 

i can make it work using this:

jbang -R=-XstartOnFirstThread examples/game/Pong.java

not sure if adding //RUNTIME_OPTIONS -XstartOnFirstThread` to it will have bad impact on windows/linux?

@maxandersen
Copy link
Collaborator

btw. i'm surprised the fix worked ...trying to grok if bug or feature :)

@maxandersen
Copy link
Collaborator

remarkably fatjar of that is "only 3.7mb...

@wfouche
Copy link
Contributor Author

wfouche commented Aug 19, 2025

I've disabled the main thread check using runtime option -Dorg.lwjgl.glfw.checkThread0=false.

@maxandersen , please check if this resolves the macOS issue. -XstartOnFirstThread does not work on Windows, so cannot be used.

@maxandersen
Copy link
Collaborator

I no longer get an error but now it just hangs/doing nothing.

jbang -R=-XstartOnFirstThread examples/game/Pong.java still works

what error are you getting on windows?

@wfouche
Copy link
Contributor Author

wfouche commented Aug 19, 2025

There currently is no way to get this to work without explicitly specifying the -XstartOnFirstThread option when running the program on macOS. I think we need a way of specifying OS specific runtime options that will only be used if a particular OS is detected. For example

//RUNTIME_OPTIONS  -Xmx2g
//RUNTIME_OPTIONS:MACOS -XstartOnFirstThread

will set the heap size to 2GB for all platforms and only on MacOS also add option -XstartOnFirstThread

One could extend this to also allow specifying an optional ARCH_TYPE as well, but it I'm not quite sure if that's really needed.

  • //RUNTIME_OPTIONS:MACOS:ARM64

Comments?

@maxandersen
Copy link
Collaborator

See jbangdev/jbang#2186

Similar issue for //DEPS we might want to consider {key=value} being applicable to directives ... At least to things like runtime options.

@wfouche
Copy link
Contributor Author

wfouche commented Aug 25, 2025

Moved the JBang directives to file Config.java.

//usr/bin/env jbang "$0" "$@" ; exit $?

// Game developed using Google Gemini AI (2.5 Pro)

//SOURCES Config.java

import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;

...

@maxandersen
Copy link
Collaborator

Why? You plan to share that Config.java between multiple games in this repo or how?

@wfouche
Copy link
Contributor Author

wfouche commented Aug 26, 2025

Why? You plan to share that Config.java between multiple games in this repo or how?

It was an experiment. Reverted the change again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants