alexandre mommers
07/30/2024, 3:26 PM-XstartOnFirstThread
?
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"
}
}
}
Skaldebane
07/30/2024, 4:20 PMalexandre mommers
07/30/2024, 4:51 PMAlexander Maryanovsky
07/30/2024, 5:09 PMalexandre mommers
07/30/2024, 7:36 PMactual fun setSystemLookAndFeel() = UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
https://github.com/JetBrains/skiko/blob/master/skiko/src/awtMain/kotlin/org/jetbrains/skiko/Actuals.awt.kt
Moving
configureSwingGlobalsForCompose()
as the first instruction in the main function solves the issue.
My final main look's like :
@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()
}
}
Abdelilah El Aissaoui
08/02/2024, 8:59 PMalexandre mommers
08/03/2024, 9:51 AMAbdelilah El Aissaoui
08/03/2024, 12:40 PMalexandre mommers
08/03/2024, 9:55 PM