xpenatan / gdx-teavm

Run Libgdx on a webbrowser with teavm
Apache License 2.0
102 stars 17 forks source link

Errors received in generator #49

Closed customautosys closed 1 year ago

customautosys commented 2 years ago
| ERROR[0]
| Class: com/github/xpenatan/gdx/backends/teavm/TeaJSGraphics.java:42
| Method: com.github.xpenatan.gdx.backends.teavm.TeaJSGraphics.setFullscreenJSNI(Lcom/github/xpenatan/gdx/backends/web/WebGraphics;Lcom/github/xpenatan/gdx/backends/web/dom/HTMLCanvasElementWrapper;II)Z
| Text: Method com.github.xpenatan.gdx.backends.teavm.TeaJSGraphics.setFullscreen(Lcom/github/xpenatan/gdx/backends/teavm/TeaJSGraphics$FullscreenChanged;Lcom/github/xpenatan/gdx/backends/web/dom/HTMLCanvasElementWrapper;II)Z is not a proper native JavaScript method declaration: its 2th parameter has wrong type
|
| ----
|
| ERROR[1]
| Class: com/github/xpenatan/gdx/backends/teavm/TeaJSApplication.java:11
| Method: com.github.xpenatan.gdx.backends.teavm.TeaJSApplication.access$200(Lcom/github/xpenatan/gdx/backends/web/dom/typedarray/ArrayBufferWrapper;Lcom/github/xpenatan/gdx/backends/teavm/TeaJSApplication$BulletPhysicsLoadFunction;)V
| Text: Method com.github.xpenatan.gdx.backends.teavm.TeaJSApplication.initBulletWasm(Lcom/github/xpenatan/gdx/backends/web/dom/typedarray/ArrayBufferWrapper;Lcom/github/xpenatan/gdx/backends/teavm/TeaJSApplication$BulletPhysicsLoadFunction;)V is not a proper native JavaScript method declaration: its 1th parameter has wrong type

I've checked the methods, I don't see what's wrong or how they should be modified. I've checked the teavm sources and it should be supported because it's an interface. I don't understand why this error is happening.

This occurs when running the dist jar in console. I also tried to debug in Android Studio but I kept getting out of heap space even though I already set -Xmx8192m in JVM options in the run configurations (not sure why maybe it's not working):

org.teavm.hppc.BufferAllocationException: Not enough memory to allocate buffers for rehashing: 0 -> 65,536
    at org.teavm.hppc.IntHashSet.allocateBuffers(IntHashSet.java:739)
    at org.teavm.hppc.IntHashSet.ensureCapacity(IntHashSet.java:364)
    at org.teavm.hppc.IntHashSet.<init>(IntHashSet.java:129)
    at org.teavm.hppc.IntHashSet.<init>(IntHashSet.java:110)
    at org.teavm.hppc.IntHashSet.<init>(IntHashSet.java:101)
    at org.teavm.dependency.DependencyAnalyzer.schedulePropagation(DependencyAnalyzer.java:352)
    at org.teavm.dependency.DependencyNode.scheduleMultipleTypes(DependencyNode.java:189)
    at org.teavm.dependency.Transition.mergeDomains(Transition.java:69)
    at org.teavm.dependency.Transition.propagate(Transition.java:61)
    at org.teavm.dependency.Transition.consume(Transition.java:151)
    at org.teavm.dependency.DependencyAnalyzer.schedulePropagation(DependencyAnalyzer.java:347)
    at org.teavm.dependency.DependencyNode.scheduleMultipleTypes(DependencyNode.java:189)
    at org.teavm.dependency.DependencyNode.propagate(DependencyNode.java:144)
    at org.teavm.dependency.DependencyNode.connectWithoutChildNodes(DependencyNode.java:320)
    at org.teavm.dependency.DependencyNode.connect(DependencyNode.java:271)
    at org.teavm.dependency.DependencyNode.connect(DependencyNode.java:394)
    at org.teavm.dependency.VirtualCallConsumer.consume(VirtualCallConsumer.java:91)
    at org.teavm.dependency.DependencyAnalyzer.schedulePropagation(DependencyAnalyzer.java:309)
    at org.teavm.dependency.DependencyNode.scheduleSingleType(DependencyNode.java:96)
    at org.teavm.dependency.DependencyNode.propagate(DependencyNode.java:68)
    at org.teavm.dependency.Transition.propagate(Transition.java:51)
    at org.teavm.dependency.Transition.consume(Transition.java:39)
    at org.teavm.dependency.DependencyAnalyzer.processNodeToNodeTransitionQueue(DependencyAnalyzer.java:669)
    at org.teavm.dependency.DependencyAnalyzer.processQueue(DependencyAnalyzer.java:641)
    at org.teavm.dependency.DependencyAnalyzer.processDependencies(DependencyAnalyzer.java:683)
    at org.teavm.vm.TeaVM.build(TeaVM.java:379)
    at com.github.xpenatan.gdx.backends.teavm.CustomTeaVMTool.generate(CustomTeaVMTool.java:402)
    at com.github.xpenatan.gdx.backends.teavm.TeaBuilder.build(TeaBuilder.java:201)
    at com.github.xpenatan.gdx.html5.generator.core.viewmodel.GeneratorViewModel$1.run(GeneratorViewModel.java:78)
Caused by: java.lang.OutOfMemoryError: Java heap space
    at org.teavm.hppc.IntHashSet.allocateBuffers(IntHashSet.java:736)
    ... 28 more

Otherwise, is there any way to add the backend to my existing libgdx project instead of using the generator? My project uses gdx-liftoff.

xpenatan commented 2 years ago

Hi @siauderman

Error 0 and 1 happens when "teavm-cli-0.7.0-dev-1200.jar" classes are inside accepted libs. It should be in "Not Accepted Libs ClassPath"

Is the generator a standalone jar ou being executed with gradle run command ? Check if teavm-cli-0.7.0-dev-1200.jar is not merging with other jar files.

customautosys commented 2 years ago

I built it as a standalone jar using the dist task because nothing I did could avoid the out of memory error when I run the "run" task.

How do I change it to "Not Accepted Libs" if I build using dist?

customautosys commented 2 years ago

Also, I just tried running on my Linux machine to see if there's a difference and I got this:

com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: /tmp/libgdxcustomautosys/53b4eafc/libimgui64.so: libimgui-cpp64.so

Any idea why there seems to be a missing native lib?

xpenatan commented 2 years ago

The generator uses imgui for the UI and its a known issue that the linux libs are not working.

xpenatan commented 2 years ago

About the dist. its not working well. The teavm cli lib is being added along with the generator classes.

Need to find a way to separate it from the final jar. Or, if possible. a way to filter its classes from messing up the emulation classes.

xpenatan commented 2 years ago

When running the run gradle command the teavm does not merge its classes so its easier to filter it out.

xpenatan commented 2 years ago

Hi @siauderman I commited a temp way to run the generator.

on windows, execute the generator gradle dist command and then run the "\tools\generator\desktop\run.bat"

See if it works this way.

customautosys commented 2 years ago

Dear @xpenatan,

Thanks for responding so quickly and sorry for bothering you!

I'm now getting this error instead:

#################################################################
| ERROR[0]
| Class: -
| Method: com.badlogic.gdx.utils.reflect.Field.getElementType(Ljava/lang/Class;Ljava/lang/String;I)Ljava/lang/Class;
| Text: Error accessing proxy method com.badlogic.gdx.utils.reflect.Field.getElementType(Lorg/teavm/metaprogramming/ReflectClass;Lorg/teavm/metaprogramming/Value;Lorg/teavm/metaprogramming/Value;)V: java.lang.NoSuchMethodException: com.badlogic.gdx.utils.reflect.Field.getElementType(org.teavm.metaprogramming.ReflectClass, org.teavm.metaprogramming.Value, org.teavm.metaprogramming.Value)
        at java.lang.Class.getDeclaredMethod(Class.java:2130)
        at org.teavm.metaprogramming.impl.UsageGenerator.getJavaMethod(UsageGenerator.java:259)
        at org.teavm.metaprogramming.impl.UsageGenerator.installProxyEmitter(UsageGenerator.java:69)
        at org.teavm.metaprogramming.impl.MetaprogrammingDependencyListener.methodReached(MetaprogrammingDependencyListener.java:78)
        at org.teavm.dependency.DependencyAnalyzer.linkMethod(DependencyAnalyzer.java:431)
        at org.teavm.dependency.DependencyAnalyzer.linkMethod(DependencyAnalyzer.java:440)
        at org.teavm.dependency.DependencyGraphBuilder$1.invokeSpecial(DependencyGraphBuilder.java:341)
        at org.teavm.dependency.AbstractInstructionAnalyzer.invoke(AbstractInstructionAnalyzer.java:196)
        at org.teavm.model.InstructionReadVisitor.visit(InstructionReadVisitor.java:182)
        at org.teavm.model.instructions.InvokeInstruction.acceptVisitor(InvokeInstruction.java:82)
        at org.teavm.model.BasicBlock.readAllInstructions(BasicBlock.java:314)
        at org.teavm.dependency.DependencyGraphBuilder.buildGraph(DependencyGraphBuilder.java:111)
        at org.teavm.dependency.PreciseDependencyAnalyzer.processMethod(PreciseDependencyAnalyzer.java:35)
        at org.teavm.dependency.DependencyAnalyzer.lambda$scheduleMethodAnalysis$8(DependencyAnalyzer.java:498)
        at org.teavm.dependency.DependencyAnalyzer.processQueue(DependencyAnalyzer.java:656)
        at org.teavm.dependency.DependencyAnalyzer.processDependencies(DependencyAnalyzer.java:683)
        at org.teavm.vm.TeaVM.build(TeaVM.java:379)
        at com.github.xpenatan.gdx.backends.teavm.CustomTeaVMTool.generate(CustomTeaVMTool.java:402)
        at com.github.xpenatan.gdx.backends.teavm.TeaBuilder.build(TeaBuilder.java:201)
        at com.github.xpenatan.gdx.html5.generator.core.viewmodel.GeneratorViewModel$1.run(GeneratorViewModel.java:78)

Doesn't look like a problem with my code, but seems there is some issue with TeaVM / libgdx.

If I run it from Android Studio (somehow I managed to fix the out of memory error), I get this instead:

#################################################################
|
| COMPILING
|
#################################################################
java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at java.util.Arrays.copyOfRange(Arrays.java:3593)
    at org.teavm.common.IrreducibleGraphSplitter.handleStronglyConnectedComponent(IrreducibleGraphSplitter.java:313)
    at org.teavm.common.IrreducibleGraphSplitter.handleIrreducibleChildren(IrreducibleGraphSplitter.java:241)
    at org.teavm.common.IrreducibleGraphSplitter.splitLoops(IrreducibleGraphSplitter.java:220)
    at org.teavm.common.GraphUtils.splitIrreducibleGraph(GraphUtils.java:361)
    at org.teavm.model.util.AsyncProgramSplitter.split(AsyncProgramSplitter.java:201)
    at org.teavm.ast.decompilation.Decompiler.decompileAsync(Decompiler.java:142)
    at org.teavm.backend.javascript.JavaScriptTarget.decompileAsync(JavaScriptTarget.java:637)
    at org.teavm.backend.javascript.JavaScriptTarget.decompile(JavaScriptTarget.java:595)
    at org.teavm.backend.javascript.JavaScriptTarget.decompile(JavaScriptTarget.java:563)
    at org.teavm.backend.javascript.JavaScriptTarget.modelToAst(JavaScriptTarget.java:516)
    at org.teavm.backend.javascript.JavaScriptTarget.emit(JavaScriptTarget.java:355)
    at org.teavm.backend.javascript.JavaScriptTarget.emit(JavaScriptTarget.java:336)
    at org.teavm.vm.TeaVM.build(TeaVM.java:422)
    at com.github.xpenatan.gdx.backends.teavm.CustomTeaVMTool.generate(CustomTeaVMTool.java:402)
    at com.github.xpenatan.gdx.backends.teavm.TeaBuilder.build(TeaBuilder.java:201)
    at com.github.xpenatan.gdx.html5.generator.core.viewmodel.GeneratorViewModel$1.run(GeneratorViewModel.java:78)

Thanks a lot for your help, much appreciated!

Is there a way I can add the backend to my liftoff project instead of using the generator? Maybe that might help?

xpenatan commented 2 years ago

Thanks for responding so quickly and sorry for bothering you!

No problem. The more error reports the better the tool becomes.

Is there a way I can add the backend to my liftoff project instead of using the generator? Maybe that might help?

Yes but its not ready yet. It's by creating a teavm module like its done in examples. The only issue is that there no snapshots yet. You can use publishToMavenLocal task from html5 tools and add this implementation to your game teavm module:

  implementation "com.github.xpenatan.gdx-web-tools:backend-web:1.0.0-SNAPSHOT"
  implementation "com.github.xpenatan.gdx-web-tools:backend-teavm:1.0.0-ALL-SNAPSHOT"

Also needs to have mavenLocal first in repositories:

    repositories {
        mavenLocal()
               // Others repos.
    }

The libs will be generated in C:\Users\MyUser.m2\repository\com\github\xpenatan\gdx-web-tools

I'm now getting this error instead:

teaVM reflection support is very small so its hard to know if its a bug or its not supported. Can you share a small jar/source example that cause this bug ? The generator does not have a option to add reflection classees yet so I'm not sure if its because of TeaReflectionSupplier.addReflectionClass or something else.

If I run it from Android Studio (somehow I managed to fix the out of memory error), I get this instead:

Have no idea what could be the problem. What java version are you using? I use java 8 to build my examples.

customautosys commented 2 years ago

My jar is here: https://customautosys.com/tuxfight/download/TuxFight-0.0.1.jar

If you need the sources, do you have a BitBucket account? It's a private repo. I can grant you access for the purpose of improving your project if you keep it confidential (not open source).

I set the Android Studio JDK to Java 8.

Will try your suggestions tomorrow, thanks!

xpenatan commented 2 years ago

Nice game.

Yes, I have bitbucket arround, its https://bitbucket.org/xpenatan/

I tried to get any info of which class is crashing teavm but no go. Since it contains some features like MyAccount, I guess we need to disable some code to check what is causing the crash. Does this game works with GWT?

By Default, teavm skip classes if its not being called.

customautosys commented 2 years ago

For some reason BitBucket is not allowing me to add you by name, can I have your email?

It worked on GWT SuperDev after commenting out all the code that used ea-async and auth0 (it kept saying sources not available despite me copying source files and creating gwt.xml). The dist build crashes mid-game: https://customautosys.com/tuxfight/web

xpenatan commented 2 years ago

Sure, its xpenatan@gmail.com.

xpenatan commented 2 years ago

Hi @siauderman

I used the GWT branch and almost got it to compile. There is 1 issue that i cant get to work. which is the CompletableFuture class. GWT have a emulation lib but teavm does not have this class. I managed to commented out everything that use CompletableFutre but another issue popup.

I could only get the first loading screen to work. The assets are confusing, some assets are in root/asset folder while others are in core/main/images. If its possible to have everything in asset folder would be better. image

customautosys commented 2 years ago

The assets that are actually used by the game engine are in assets. Those in src are the original source image files before being packed with TexturePacker (they do not actually get bundled with the game).

Wait, TeaVM doesn't support CompletableFuture at all? Then it's not much better than GWT for me then (save maybe that I can use the Auth0 Java library - don't know if that'll work too). I was hoping to use it so that I would not have to rewrite all my ea-async code which uses await (it is "instrumented" which means the ea-async library modifies the bytecode during compile time to change all the await calls to multiple thenAcceptAsync calls with lambdas - works on both Android and desktop).

So ironic that JavaScript natively supports await, Java can support await with ea-async, but when we convert Java to JavaScript we can't use await!

xpenatan commented 2 years ago

I'll investigate it later to try to get the assets working. One step at a time.

GWT does not have CompletableFuture. OneGeek created a external lib to emulate it in GWT https://github.com/OneGeek/GWT-CompletableFuture. Someone may need to do it also for teavm.

teavm contains some classes from concurrent package but its not everything https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib/java/util/concurrent

If your game works in GWT, it will work with teavm also. But the issue is that if teavm is missing something, it needs to be implemented or ported from gwt.

customautosys commented 2 years ago

I'll investigate it later to try to get the assets working. One step at a time.

GWT does not have CompletableFuture. OneGeek created a external lib to emulate it in GWT https://github.com/OneGeek/GWT-CompletableFuture. Someone may need to do it also for teavm.

teavm contains some classes from concurrent package but its not everything https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib/java/util/concurrent

If your game works in GWT, it will work with teavm also. But the issue is that if teavm is missing something, it needs to be implemented or ported from gwt.

Yes, I'm using that CompletableFuture implementation.

Have you tried cheerpj? Supposedly it supports the entire Java 8 API.

xpenatan commented 2 years ago

Hi @siauderman. I know about cheerpj but its not free.

The free part is evaluate and testing only. If you plan to export a html game for commercial purposes you need to pay =( If you can convince them to let libgdx devs create games without issue I may take a look at.