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.24k stars 1.18k forks source link

Skiko RenderException #4105

Closed tangshimin closed 9 months ago

tangshimin commented 10 months ago

Describe the bug I have a project that needs to open a ComposePane from a SwingPane and after upgrading to compose 1.6 there is an exception message: [SKIKO] warn: Exception in draw scope org.jetbrains.skiko.RenderException: Native exception in [Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_initSwapChain], code 3221225477: EXCEPTION_ACCESS_VIOLATION

The contents of the ComposePane display fine on my computer, but I don't know what happens on other computers

Affected platforms Select one of the platforms below:

Versions

To Reproduce

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.darkColors
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.rememberDialogState
import java.awt.BorderLayout
import javax.swing.*

fun main() = SwingUtilities.invokeLater {
    val window = JFrame()
    window.setSize(800, 600)
    window.setLocationRelativeTo(null)
    window.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
    window.title = "SwingComposeWindow"
    window.background = java.awt.Color(12,12,12)

    val swingPanel = JPanel()
    swingPanel.setSize(800, 600)
    val setting = JButton("Setting")
    var isOpen = false
    // avoids white flash
    setting.addActionListener {
        if (!isOpen) {
            val composePanel = ComposePanel()
            // setting the content
            composePanel.setContent {
                ComposeContent()
            }
            window.contentPane.add(composePanel, BorderLayout.NORTH)
        }
    }
    swingPanel.add(setting)
    swingPanel.background = java.awt.Color(12,12,12)
    window.contentPane.add(swingPanel, BorderLayout.CENTER)
    window.isVisible = true
}

@Composable
fun ComposeContent() {
    var isOpen by remember { mutableStateOf(true) }
    val windowState = rememberDialogState(
        size = DpSize(500.dp, 500.dp),
        position = WindowPosition.Aligned(Alignment.Center)
    )
    MaterialTheme (colors = darkColors()) {
        if(isOpen){
            Dialog(
                title = "Setting",
                onCloseRequest = {isOpen = false},
                resizable = false,
                state = windowState,
            ) {

                Surface(
                    elevation = 5.dp,
                    shape = RectangleShape,
                ) {
                    Column(
                        horizontalAlignment = Alignment.CenterHorizontally,
                        verticalArrangement = Arrangement.Center,
                        modifier = Modifier
                            .width(500.dp)
                            .fillMaxHeight()
                            .background(MaterialTheme.colors.background)
                    ) {
                        Text("Setting 1")
                        Text("Setting 2")
                        Text("Setting 3")
                    }
                }
            }
        }
    }

}

https://github.com/JetBrains/compose-multiplatform/assets/16540656/d92115ad-a5c8-48c8-a71d-5610730b3397

okushnikov commented 4 months ago

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