ArrayIndexOutOfBoundsException during compilation
Quillraven opened this issue · 14 comments
Hi,
I was working on rewriting some old game to Kotlin and made a fresh new project with gdx-liftoff. I tried the teavm launcher at the beginning with a basic rendering setup and the ECS library with some components and systems. Everything was working great!
Now I added some new features mainly related to Box2D and now the compilation fails and I have no idea what is causing it :(
Here is the project: https://github.com/Quillraven/MysticGarden/tree/kotlin
Here is the stacktrace:
java.lang.ArrayIndexOutOfBoundsException: arraycopy: length -1 is negative
at java.base/java.lang.System.arraycopy(Native Method)
at java.base/java.util.Arrays.copyOfRange(Arrays.java:3895)
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 org.teavm.tooling.TeaVMTool.generate(TeaVMTool.java:433)
at com.github.xpenatan.gdx.backends.teavm.TeaBuilder.build(TeaBuilder.java:112)
at com.github.xpenatan.gdx.backends.teavm.TeaBuilder.build(TeaBuilder.java:105)
at com.github.quillraven.mysticgarden.teavm.TeaVMBuilder.main(TeaVMBuilder.kt:27)
Any hint is appreciated to find out the root cause of this issue.
Thank you!
I suppose it's related to following issue in TeaVM: konsoletyper/teavm#657
Yes, I think that's the same error. In some cases (code changes), I got a different number in length -1 is negative
, e.g. -3
or -9
.
unlucky, so nothing I can do at the moment?
@Quillraven you can wait until I fix the issue OR you can fix it yourself and provide a PR
I did not mean it in a rude way, sorry if you read it that way.
I don't think I am capable to fix the issue. What I meant is, if I can help somehow by providing logs or whatever or try out special local builds that you mentioned in the other thread?
Also, feel free to use the project that I linked above as a reference for the current problem. In this project you can reproduce the issue by running the buildJavascript task of the teavm project.
@Quillraven it was not rude. However, fixing the problem yourself is hard, but still possible. I think I have now enough information to fix the issue, but I don't know how long you gong to wait, since the issue is really complicated. I have a hint for you: if possible, remove Thread.wait. Thread.start, Object.wait, or any other thread-related calls from your codebase, this may help.
I am not in a hurry
From what I know I don't use any thread related things myself and actually use the normal AssetManager of LibGDX instead of an asynchronous Variant of LibKTX.
However, I don't know what some of the internals are doing e.g. in box2d and even if I would know, I cannot change it because it is library internal stuff 😅
Thanks for looking into it! Is there a way to try it out? 1.0.0-Snapshot seems to be broken and throws gradle errors and 1.0.0-b2 had the bug in it.
Will there be a 1.0.0-b3?
Did you update configuration? I removed backend-web so you have to update to Tea classes.
Yes, B3 will be up in a few minutes. I'm Just waiting to fix a repository build issue.
I just use the default gdx-liftoff setup. Will have a look again later and let you know 😊
@xpenatan I get the same errors as with the snapshot :(
Any idea why it is working with b2 but with b3 and SNAPSHOT I cannot even get the gradle sync to work? :(
I had to update some gradle stuff but still not working :(
My teavm build.gradle:
plugins {
id 'java'
id 'org.gretty' version '3.1.0'
}
gretty {
contextPath = '/'
extraResourceBase 'build/dist/webapp'
}
sourceSets.main.resources.srcDirs += [ rootProject.file('assets').path ]
project.ext.mainClassName = 'com.github.quillraven.mysticgarden.teavm.TeaVMBuilder'
eclipse.project.name = appName + '-teavm'
dependencies {
implementation "com.github.xpenatan.gdx-teavm:gdx-box2d-teavm:$gdxTeaVMVersion"
implementation "com.github.xpenatan.gdx-teavm:backend-teavm:$gdxTeaVMVersion"
implementation project(':core')
}
task buildJavaScript(dependsOn: classes, type: JavaExec) {
setDescription("Transpile bytecode to JavaScript via TeaVM")
mainClass.set(project.mainClassName)
setClasspath(sourceSets.main.runtimeClasspath)
}
build.dependsOn buildJavaScript
task run(dependsOn: [buildJavaScript, ":teavm:jettyRun"]) {
setDescription("Run the JavaScript application hosted via a local Jetty server at http://localhost:8080/")
}
the root gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'https://s01.oss.sonatype.org' }
mavenLocal()
google()
gradlePluginPortal()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
maven { url "https://teavm.org/maven/repository/" }
}
dependencies {
classpath "com.android.tools.build:gradle:$androidPluginVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
}
configure(subprojects - project(':android')) {
apply plugin: 'java-library'
apply plugin: 'kotlin'
sourceCompatibility = 1.8
compileJava {
options.incremental = true
}
}
subprojects {
version = '1.0.0'
ext.appName = 'MysticGarden'
repositories {
mavenCentral()
maven { url 'https://s01.oss.sonatype.org' }
mavenLocal()
gradlePluginPortal()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://jitpack.io' }
maven { url 'https://teavm.org/maven/repository/' }
}
}
eclipse.project.name = 'MysticGarden' + '-parent'
I think you need java 11.
Thanks for the hint!
Adjusting the sourceCompatibility
from 1.8 to 11 in the different gradle files did the trick.
Then I had to adjust a few imports in the teavm project because of the removal of the web
package.
Then I was able to compile it but it still did not run. Error was that my particle files are using an old format which worked in lwgjl3 but not in teavm. So I downloaded the latest particle editor opened and saved my effects once more and tadaaaa:
I don't hear music or sound and I cannot remember if it did that in my other project. Will need to check that again but at least the game with box2d, box2d-light and Fleks ECS is running!
Thanks for the help and hotfix :)
edit: audio is working btw. I checked it again today and the problem was that Firefox blocked it. I had to unblock it and refresh the page then audio was also playing!