I have some code that behaves differently when run...
# compose-desktop
d
I have some code that behaves differently when run from a fresh template CfD project's
runDistributable
than when run from
run
, from a Java CLI jar, or from a Kotlin CLI jar. Here's the full code of the application (the rest is as generated from the CfD template)
Copy code
fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        Button(onClick = {
            ProcessBuilder(
                "C:\\Program Files (x86)\\Fractal Softworks\\Starsector1.95.1-RC6\\starsector.exe"
            )
                .directory(File("C:\\Program Files (x86)\\Fractal Softworks\\Starsector1.95.1-RC6"))
                .start()

        }) {
            Text("Hello Madness")
        }
    }
}
The actual issue is hard to describe;
starsector.exe
launches a java-based game that runs on its own jre 7/8. The game crashes only when launched from CfD dist because it's unable to resolve some relative file paths that are passed to it from `starsector.exe`as jvm params. Mimicking the functionality of the
exe
with a custom
java -jar
thing fixes the issue if I use absolute paths for the game files, but this has other side effects (like any windows compat settings applied to the
exe
aren't used since I'm working around it. I don't want to work around the problem; the code works everywhere except as a CfD dist. I can take that
ProcessBuilder
code, put it into a pure java or kotlin CLI program, compile a jar, run it, and it'll run the game just fine. Literally it's only when run from
runDistributable
(or from the
.exe
built from
createDistributable
). Any ideas? What's being done differently by CfD's dist exe?
a
Did you try to pass args to ProcessBuilder?
ProcessBuilder("C:\\my-file.exe", "arg_one", "arg_two")
d
yes, i've tried probably anything you'll easily find on stackoverflow
why would that code work differently when run from
app.exe
generated from
buildDistributable
than when run from
run
?
I also used VisualVM to check launched and system variables for when the bug does and doesn't reproduce, and they are the same, confirmed via Beyond Compare
a
maybe process tied to parent. Does app.exe closes immediatly after executing? try to spawn somehing like "demon process"
d
no, it stays open
i've tried with and without waiting for the subprocess to finish and on main/io threads
a
launch as admin
d
probably the second thing i tried
a
also try path without spaces
d
yes i tried that days ago
it would take too long to list everything i've tried
which is why i'm emphasizing that the code works everywhere except in CfD Dist
it's something that is being done by Compose
a
Would be nice to have repo to reproduce (simplified version with dummy executable to consume path).
d
yeah, unfortunately the only symptom occurs in Starsector, which is $15, heh
the game is able to load its other assets, it's not as simple as being unable to launch a java program
a
how does code/command where you pass path looks like?
That's about "with a custom `java -jar`"
d
Copy code
java.exe -XX:CompilerThreadPriority=1 -XX:+CompilerThreadHintNoPreempt -Djava.library.path=native\\windows -Xms1536m -Xmx1536m -Xss2048k -classpath janino.jar;commons-compiler.jar;commons-compiler-jdk.jar;starfarer.api.jar;starfarer_obf.jar;jogg-0.0.7.jar;jorbis-0.0.15.jar;json.jar;lwjgl.jar;jinput.jar;log4j-1.2.9.jar;lwjgl_util.jar;fs.sound_obf.jar;fs.common_obf.jar;xstream-1.4.10.jar -Dcom.fs.starfarer.settings.paths.saves=..\\saves -Dcom.fs.starfarer.settings.paths.screenshots=..\\screenshots -Dcom.fs.starfarer.settings.paths.mods=..\\mods -Dcom.fs.starfarer.settings.paths.logs=. com.fs.starfarer.StarfarerLauncher
changing all of the relative paths to absolute ones allows me to launch the program directly, without a crash, bypassing the game's
.exe
launcher
but as mentioned that isn't a real solution
because it causes other problems
a
Try to write executable that would print consumed path to file/console to see what's coming from different dist
to replace starsector.exe
d
would that be different information than what i'm seeing from VisualVM?
message has been deleted
message has been deleted
a
path as args -> compose app -> starsector.exe? if so then yes, we don't know how ProcessBuilder exactly works, there is might be some encoding tricks (asci / utf-8 etc)
d
compose app uses ProcessBuilder/Runtime.exec -> calls starsector.exe -> launches jar
i wrote a simple kotlin jvm app that spit out a .bat and pointed the CfD hello world tester at it
here's the jvm app's code
Copy code
println("Program arguments: ${args.joinToString()}")
Path.of("./launcherlog.log")
    .writeText(
        buildString {
            appendLine("args:" + args.joinToString())
            appendLine("env:" + System.getenv().entries.joinToString { "${it.key}=${it.value}" })
        })
i called that from both
run
and
runDistributable
on the CfD side to see what was different
nothing was
binary same, tested twice to make sure
I have also tried doing CfD ->
.bat
-> game jar files and not using the game's
.exe
, but that doesn't work either, same error as always but works when not using
runDistributable
no difference between System.getProperties(), either
a
According to https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution runDistributable differs from run in a way that it uses prepackaged JVM i.e. it's own JRE try to inspect diffs between default JRE used in your OS (env variables) and that one from runDistributable.
d
A friend created a native
.dll
that launches Starsector and we managed to call that native code from a Hello world CfD app
and the problem still occurs
He compiled it from Rust and uses the exact same code in a Rust-only program to launch the game without issues
So CfD
runDistributable
-> native windows code that launches -> Starsector.exe still fails
Copy code
Command::new(install_dir.join("starsector.exe"))
      .current_dir(install_dir)
      .spawn()
is his simple launch code, minus all of the other JNI insanity
I even tried launching a CfD app and then launching the game normally (double click the exe) just to see if it's merely running CfD that causes the problem, but that didn't have a problem
How can launching the program from native still reproduce the bug?!
I would be assuming it was something specifically weird/dumb on my side, except that • it happens on multiple peoples' computers • it happens with a basic Hello World program • it works with
run
but not
runDistributable
a
d
Yep, tried that
also tried including only the needed modules
and with/without console
and installed from msi
Issue still unsolved, no idea where to go from here. Will update this if I ever get anyway with it
a
@David W how does it fail for you? I’ve tried running the exact same game with the snippet above, and it worked both running from IDEA and trough runDistributable and running .exe from explorer
d
@alexey.tsvetkov It shows a popup immediately at the start of loading with an error about OpenAL (which is caused by lwjgl not finding the OpenAL dlls on any paths, despite the game's vmparams file sending the location) and then crashes at the end of loading with a follow-on error that's essentially just a fatal version of the first. • Make sure you don't have any OpenAL dlls on your system's path, eg in System32. • Make sure the checkbox on the game's launcher to enable sound is enabled (it doesn't crash if it doesn't try to load OpenAL). Also, even if it can load OpenAL from somewhere, it won't get the paths for the game's mods, saves, and log folders correct (they are also passed in by vmparams file).
Thank you for spending any time at all on this!
I'm making a video demo of the issue
Accidentally used a viewport of 1440p, my other monitor's res, sorry about that.
The Starsector installation is fresh and unmodified.
a
@David W can you try to do the following: 1. Delete existing `<INSTALL_DIR>/starsector-core/starsector.log`; 2. Add
-Dorg.lwjgl.util.Debug=true
to the `<INSTALL_DIR>/vmparams`; 3. Reproduce the issue; 4. Share the resulting
starsector.log
?
I wasn’t able to reproduce myself, unless I explicitly delete
starsector-core\native\windows\OpenAL64.dll
, which seems to indicate, that the right version of OpenAL is loaded (also, I use a fresh install of Windows 10, so I doubt there would be a system-wide OpenAL). The sound is working in both cases with my computer. I’m really intrigued by the issue. No explanation so far, though
d
I actually spent a while trying to compile my own version of LWJGL with debug statements but couldn't get one that didn't crash the game despite compiling from the same version source that the game uses...
This is what I got after making only that vmparams change 😞
If I remove that arg from vmparams, then it goes back to the OpenAL error after pressing Play on the launcher
Incidentally, I think that stack underflow error is the same one that I got when trying to use my own compiled LWJGL .jar file. Probably not relevant, though. Probably.
Running Starsector in Windows Sandbox is a no-go, even with vGPU enabled, so I can't easily test on a new Windows install. Since other users have had the exact same crash, though, it's not a total unicorn.
a
I also don’t have this issue. The OpenGL issue is probably not relevant, but I’m not sure, how to debug without working around it. Maybe could try to build your version of LWJGL with modified https://github.com/LWJGL/lwjgl/blob/2df01dd762e20ca0871edb75daf670ccacc89b60/src/java/org/lwjgl/LWJGLUtil.java#L513 then just replace LWJGLUtil.class (to always log). I’m not sure if it helps though. Another guess is maybe to try updating graphics cards driver, turning off G-Sync/VRR (if enabled), forcing 60 Hz and using one display only (not for the original issue, but just to make sure, that Stack Underflow is not caused by some exotic harware/driver (it seems you’re using 360 Hz display, which seems to be exotic))
d
My system, latest nvidia drivers. Not sure if any users with/out the crash used AMD, but so far evidence has pointed me toward it being an issue with environment variables not being passed on.
I'll see if I can get past that stack underflow, yeah.
a
with environment variables not being passed on
That could be it, but I thought you’ve compared the env vars of a dummy launched process?
d
True, I did and they were the same. Somehow it's not picking up any of the relative paths in vmparams, though, and I don't know what else would be the culprit.
Or, rather, not resolving those relative paths to the right base folder.
(as using absolute paths 'fixes' the OpenAL error and the other issues - not finding mods/saves/log)
a
Another debugging idea: try importing LWJGL into Intellij, starting starsector, attaching to the JVM process and adding a breakpoint here https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/openal/AL.java#L138
d
ha, I've tried that before but never got the debugger to stop at the breakpoints.
a
:(
d
No luck getting past that stack underflow, I disabled Xbox game bar, background recording, BAR scheduling, Game Mode, exited Steam, unplugged ext monitors, set display to 60hz, rebooted, and probably a few other things.
I have a partition I can wipe to do a fresh install of Windows, I'll try that
Still waiting on backup to install Windows, but I managed to get the console output of the game crashing from the buffer underflow with LWJGL debug enabled....it's weird
every door has a curse behind it
Got that log with LWJGL debug enabled and bypassed the stack underflow error by launching the game directly, bypassing the launcher, which results in the same OpenAL crash.
Copy code
[LWJGL] Initial mode: 1920 x 1080 x 32 @360Hz
[LWJGL] Found 92 displaymodes
[LWJGL] Removed 60 duplicate displaymodes
[LWJGL] MemoryUtil Accessor: AccessorUnsafe
[LWJGL] getPathFromClassLoader: searching for: OpenAL64
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: sun.misc.Launcher$AppClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.net.URLClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.security.SecureClassLoader.findLibrary(java.lang.String)
[LWJGL] getPathFromClassLoader: searching for: lwjgl
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: sun.misc.Launcher$AppClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.net.URLClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.security.SecureClassLoader.findLibrary(java.lang.String)
[LWJGL] Found 3 OpenAL paths
[LWJGL] Testing 'native\\windows\OpenAL64.dll'
[LWJGL] Failed to load native\\windows\OpenAL64.dll: Could not load OpenAL library (126)
[LWJGL] Testing 'C:\Program Files (x86)\Fractal Softworks\Starsector-do-not-touch\starsector-core\OpenAL64.dll'
[LWJGL] Failed to load C:\Program Files (x86)\Fractal Softworks\Starsector-do-not-touch\starsector-core\OpenAL64.dll: Could not load OpenAL library (126)
[LWJGL] Testing 'OpenAL64.dll'
[LWJGL] Failed to load OpenAL64.dll: Could not load OpenAL library (126)
[LWJGL] *** Alert *** Starsector 0.95.1a-RC6
Error in sound initialization, proceeding with sound disabled.

org.lwjgl.openal.AL10.nalDistanceModel(I)V

[LWJGL] *** Alert *** Starsector 0.95.1a-RC6
Fatal: org.lwjgl.openal.AL10.nalListenerfv(IJ)V
Check starsector.log for more info.
The LWJGL debug output isn't sent to starsector.log, so this is a copy/paste from the console.
The above is when I run Compose from a distributable.
Here is the same, but run from
run
in IntelliJ (where the game runs as expected, no crash):
Copy code
[LWJGL] Initial mode: 1920 x 1080 x 32 @360Hz
[LWJGL] Found 92 displaymodes
[LWJGL] Removed 60 duplicate displaymodes
[LWJGL] MemoryUtil Accessor: AccessorUnsafe
[LWJGL] getPathFromClassLoader: searching for: OpenAL64
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: sun.misc.Launcher$AppClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.net.URLClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.security.SecureClassLoader.findLibrary(java.lang.String)
[LWJGL] getPathFromClassLoader: searching for: lwjgl
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: sun.misc.Launcher$AppClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.net.URLClassLoader.findLibrary(java.lang.String)
[LWJGL] Failed to locate findLibrary method: java.lang.NoSuchMethodException: java.security.SecureClassLoader.findLibrary(java.lang.String)
[LWJGL] Found 3 OpenAL paths
[LWJGL] Testing 'native\\windows\OpenAL64.dll'
[LWJGL] Found OpenAL at 'native\\windows\OpenAL64.dll'
On a fresh install of Windows 10, Starsector crashes for me with the OpenAL error when launched from the distributable.