Anyone know why my compose app does not showing up...
# compose-desktop
a
Anyone know why my compose app does not showing up when I start the app with
-XstartOnFirstThread
?
Copy code
compose.desktop {
    application {
        mainClass = "MainKt"

        jvmArgs += "--add-opens=java.base/java.lang=ALL-UNNAMED"

        if (Platform.os == Os.MacOs) {
            jvmArgs.add("-XstartOnFirstThread")
        }

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "org.example.project"
            packageVersion = "1.0.0"
        }
    }
}
s
Are you getting a crash? If so, posting the stacktrace might help. If not, post any warning logs you're seeing.
a
Not it is just not showing, if I remove it, that working. I need this option to run Mac functions that need to be run on the first thread.
a
Try running the compose part on a different thread.
a
@Alexander Maryanovsky Thanks, but that wasn't enough. After debugging, I found that the program gets stuck at the line :
Copy code
actual fun setSystemLookAndFeel() = UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
https://github.com/JetBrains/skiko/blob/master/skiko/src/awtMain/kotlin/org/jetbrains/skiko/Actuals.awt.kt Moving
Copy code
configureSwingGlobalsForCompose()
as the first instruction in the main function solves the issue. My final main look's like :
Copy code
@file:OptIn(ExperimentalComposeUiApi::class)

import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.configureSwingGlobalsForCompose
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import io.ygdrasil.wgpu.GLFWContext
import io.ygdrasil.wgpu.WGPU.Companion.loadLibrary
import io.ygdrasil.wgpu.glfwContextRenderer
import io.ygdrasil.wgpu.internal.jvm.panama.WGPULogCallback
import io.ygdrasil.wgpu.internal.jvm.panama.wgpu_h
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
import org.lwjgl.glfw.GLFW.glfwPollEvents
import org.lwjgl.glfw.GLFW.glfwWindowShouldClose
import java.lang.foreign.Arena
import java.lang.foreign.MemorySegment

val callback = WGPULogCallback.allocate({ level, message, data ->
    println("LOG {$level} ${message.getString(0)}")
}, Arena.global())

var glfwContext: GLFWContext? = null

fun main() {
    configureSwingGlobalsForCompose()
    loadLibrary()
    wgpu_h.wgpuSetLogLevel(1)
    wgpu_h.wgpuSetLogCallback(callback, MemorySegment.NULL)

    val composeThread = Thread {
        println("thread started")
        application {
            println("compose")
            Window(
                onCloseRequest = ::exitApplication,
                title = "TestPorject",
            ) {
                println("compose")
                App(glfwContext?.wgpuContext)
            }
        }
    }

    runBlocking {

        glfwContext = glfwContextRenderer(width = 512, height = 512, deferredRendering = true)

        println("will run compose app")
        composeThread.start()
        println("will wait now on this one")

        while (!glfwWindowShouldClose(glfwContext!!.windowHandler)) {
            glfwPollEvents()
            yield()
        }

        glfwContext!!.close()
    }
}
a
Are you trying to run compose on top of WGPU? I've done a similar thing using Winit as I would like to have native binaries in graalvm but skiko has been a huge pain to deal with, as it depends directly on AWT. Skija doesn't but then you would need to adapt a lot of code in compose to use skija 🤷‍♂️
a
That's right, I create a context from a GLFW window on desktop and a canvas on web, then render my scene to a texture. The texture is exported to a buffer which is converted into a Compose Image. It's not memory efficient but it works. In the long term, it would be nice to have WGPU support in Skia.
👍 1
a
Interesting! In my case I've resorted to https://github.com/rust-windowing/glutin When drawing with Skija + GraalVM I saw a considerable reduction of memory usage compared to Skiko +JVM. Anyway, good luck with your project 😃
👍 1
a
Thanks for the feedback !