xpenatan/gdx-teavm

Kotlin 1.9.x AtomicReferenceFieldUpdater was not found

Quillraven opened this issue · 7 comments

I recently updated two of my projects to Kotlin 1.9.10 and I found out that they no longer work with TeaVM because of:

#################################################################
|
| Compiler problems
|
#################################################################
| Class: kotlin/LazyJVM.kt:124
| Method: kotlin.SafePublicationLazyImpl.<clinit>()V
| Text: Class java.util.concurrent.atomic.AtomicReferenceFieldUpdater was not found

I use 1.0.0-b7 version and I can confirm that everything works with Kotlin 1.8.x (1.8.22 for example).

Any idea why I get this problem in Kotlin 1.9.10 and how to fix it?

I tried the following without success:

  • Upgrade to 1.9.20-RC
  • Downgrade to 1.9.0
  • Change TeaVM to 1.0.0-SNAPSHOT (that actually adds a second compiler error
    | Class: -
    | Method: com.github.xpenatan.gdx.backends.teavm.TeaGL20.compareObject(Lorg/teavm/jso/JSObject;Lorg/teavm/jso/JSObject;)Z
    | Text: Native method com.github.xpenatan.gdx.backends.teavm.TeaGL20.compareObject(Lorg/teavm/jso/JSObject;Lorg/teavm/jso/JSObject;)Z has no implementation
    

was not found means that teavm does not have the class implemented.

I guess kotlin 1.9.10 is using it and teavm for some reason is trying to parse it now.

TeaGL20 you can ignore, it should work with this error. I think the problem started when I added Emulate anotation in GL20. I'll try a different approuch.

Hey @Quillraven.

Can you try the snapshots? I just updated to teavm version 0.9.0 and from the release note it now supports AtomicReferenceFieldUpdater. https://github.com/konsoletyper/teavm/releases/tag/0.9.0

I have good and bad news!

Good: both compilation errors are gone and one of the games is working again using the SNAPSHOT version!

Bad: the other game still does not work. I can see the LibGDX logo and the first few frames of the game, which is better than before. I also see some debug messages in the browser console. But after a few frames it simply freezes and I get the browser popup that the page is not reacting and if I want to close it.

Working: https://github.com/Quillraven/MysticGarden/tree/kotlin
Not-working: https://github.com/Quillraven/MysticWoods/tree/fleks-2.0

For mysticwoods. Its a deadlock somewhere. Its getting inside a loop and cant escape.

I sent you video on discord

Cool - will have a look in more detail tomorrow. I know that it worked before with Fleks 2.4 (ECS) and TeaVM 1.0.0.b7. I think the normal desktop backend is also still working. That is what I used to check if Fleks 2.5 has any sideeffects.

I will see if something has changed in findNearbyEnemies or if I can rewrite it to avoid the deadlock.

fyi: before this project did not work because it used GdxAI with some special annotations to pass info from a .tree file to a AI task. I updated that recently as well to the latest LibKTX version which supports a DSL for behavior tree creation. With that change, this project was then successfully running as well in the browser because the annotations + reflection stuff was no longer needed :)

I quote myself from Discord:

The problem is using "mutableSetOf()". For whatever reason this causes the deadlock. Using "hashSetOf()" is working. The difference is, that mutableSetOf is using a LinkedHashSet while hashSetOf uses a HashSet.
No idea why this is a problem since Kotlin 1.9.x but it is rather simple to fix 😉

Thank you for pointing me to the function that caused the issue!