JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.15k stars 1.17k forks source link

WASM CanvasBasedWindow illegal cast #3436

Closed eygraber closed 1 year ago

eygraber commented 1 year ago

Describe the bug Getting a RuntimeError: illegal cast

Uncaught RuntimeError: illegal cast
    at <com.eygraber:webApp>.androidx.compose.ui.window.CanvasBasedWindow$lambda.invoke (ComposeWindow.js.kt:156:13)
    at <com.eygraber:webApp>.androidx.compose.ui.window.CanvasBasedWindow$lambda.invoke (ComposeWindow.js.kt:163:14)
    at <com.eygraber:webApp>.androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.wasm.kt:107:22)
    at <com.eygraber:webApp>.androidx.compose.ui.window.ComposableLambda$invoke$ref.invoke (ComposeWindow.js.kt:141:17)
    at <com.eygraber:webApp>.androidx.compose.ui.window.ComposableLambda$invoke$ref.invoke (ComposeWindow.js.kt:141:17)
    at <com.eygraber:webApp>.androidx.compose.runtime.CompositionLocalProvider (CompositionLocal.kt:228:5)
    at <com.eygraber:webApp>.androidx.compose.ui.ComposeScene$setContent$lambda.invoke (ComposeScene.skiko.kt:382:13)
    at <com.eygraber:webApp>.androidx.compose.ui.ComposeScene$setContent$lambda.invoke (ComposeScene.skiko.kt:385:14)
    at <com.eygraber:webApp>.androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.wasm.kt:107:22)
    at <com.eygraber:webApp>.androidx.compose.ui.ComposableLambda$invoke$ref.invoke (ComposeScene.skiko.kt:380:15)

Affected platforms

Versions

To Reproduce Run gradle :sample:webApp:wasmRun from https://github.com/eygraber/compose-color-picker/tree/wasm

dima-avdeev-jb commented 1 year ago

@eymar Need to checkout branch wasm. One line command to reproduce: git clone https://github.com/eygraber/compose-color-picker.git -b wasm && cd compose-color-picker && ./gradlew :sample:webApp:wasmRun

eymar commented 1 year ago

It's an issue in kotlin/wasm: https://youtrack.jetbrains.com/issue/KT-60113/K-Wasm-illegal-cast-when-using-1.9.20-dev

UPD: while the error message is the same, the issue described here could be different. Reopening for now to investigate.

eymar commented 1 year ago

@eygraber I'm not sure exactly what's going on, but I guess some gradle plugins you have applied in the project could override the compose compiiler version?

No runtime exception with this patch:

Index: sample/shared/build.gradle.kts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/sample/shared/build.gradle.kts b/sample/shared/build.gradle.kts
--- a/sample/shared/build.gradle.kts    (revision 17b929343fc8c13799d7935408900648bbdce7c3)
+++ b/sample/shared/build.gradle.kts    (date 1690965352680)
@@ -30,3 +30,5 @@
     }
   }
 }
+
+compose.kotlinCompilerPlugin.set("1.4.0-dev-wasm09")
\ No newline at end of file
Index: sample/webApp/build.gradle.kts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/sample/webApp/build.gradle.kts b/sample/webApp/build.gradle.kts
--- a/sample/webApp/build.gradle.kts    (revision 17b929343fc8c13799d7935408900648bbdce7c3)
+++ b/sample/webApp/build.gradle.kts    (date 1690965288287)
@@ -41,4 +41,6 @@
   web.application {}
 }

+compose.kotlinCompilerPlugin.set("1.4.0-dev-wasm09")
+
 rootProject.the<NodeJsRootExtension>().versions.webpack.version = "5.76.2"
Index: library/build.gradle.kts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/library/build.gradle.kts b/library/build.gradle.kts
--- a/library/build.gradle.kts  (revision 17b929343fc8c13799d7935408900648bbdce7c3)
+++ b/library/build.gradle.kts  (date 1690965288275)
@@ -38,3 +38,5 @@
     // }
   }
 }
+
+compose.kotlinCompilerPlugin.set("1.4.0-dev-wasm09")
\ No newline at end of file

And the color picker is visible on the screen

eymar commented 1 year ago

Feel free to reopen if necessary.

eygraber commented 1 year ago

Thank you, I forgot I made a change to how I override the compiler and didn't update that after merging it into my wasm branch. Sorry about that.

okushnikov commented 3 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.