xpenatan / gdx-teavm

Run Libgdx in a webbrowser with teavm
Apache License 2.0
107 stars 16 forks source link

Kotlin 1.9.x AtomicReferenceFieldUpdater was not found #111

Closed Quillraven closed 10 months ago

Quillraven commented 10 months ago

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:

xpenatan commented 10 months ago

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.

xpenatan commented 10 months ago

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

Quillraven commented 10 months ago

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

xpenatan commented 10 months ago

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

xpenatan commented 10 months ago

I sent you video on discord

Quillraven commented 10 months ago

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 :)

Quillraven commented 10 months ago

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!