Skip to content

SkiaLayer is disposed #408

Description

@Dakkakk

compose-multiplatform-version = "1.11.1"
compose-webview-multiplatform="2.0.3"

When I Trying to exit application, it says"SkiaLayer is disposed”
I have tried to fix it for hours and no way.

Minimal Reproduce Code:

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowScope
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import cn.luckcc.exam.lister.ui.modified.WindowDraggableArea
import com.multiplatform.webview.util.addTempDirectoryRemovalHook
import dev.datlag.kcef.KCEF
import dev.datlag.kcef.KCEFBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import kotlin.math.max
import kotlin.system.exitProcess

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun WindowScope.PacsWebViewPrev(
    onCloseRequest: () -> Unit,
) {
    var restartRequired by remember { mutableStateOf(false) }
    var downloading by remember { mutableStateOf(0F) }
    var initialized by remember { mutableStateOf(false) }
    val download: KCEFBuilder.Download = remember { KCEFBuilder.Download.Builder().github().build() }
    LaunchedEffect(Unit) {
        withContext(Dispatchers.IO) {
            KCEF.init(
                builder = {
                    installDir(File("kcef-bundle"))
                    progress {
                        onDownloading {
                            downloading = max(it, 0f)
                        }
                        onInitialized {
                            initialized = true
                        }
                    }
                    settings {
                        cachePath = File("cache").absolutePath
                    }
                },
                onError = {
                    it?.printStackTrace()
                },
                onRestartRequired = {
                    restartRequired = true
                }
            )
        }
    }
    if (restartRequired) {
        Text("Restart required")
    } else if (!initialized) {
        Text("Downloading $downloading%")
    } else {
        Column {
            WindowDraggableArea {
                CenterAlignedTopAppBar(
                    title = {
                        Text("PacsPreview")
                    },
                    navigationIcon = {
                        IconButton(onClick = onCloseRequest) {
                            Icon(Icons.Default.Close, contentDescription = "Close")
                        }
                    },
                )
            }
            PacsWebView()
        }
    }
}

fun main() = application {
    addTempDirectoryRemovalHook()
    Window(
        onCloseRequest = ::exitApplication,
        state = rememberWindowState(size = DpSize(500.dp, 300.dp)),
        undecorated = true,
        title = "PacsWebView",
        resizable = true
    ) {
        PacsWebViewPrev(
            onCloseRequest = {
                KCEF.disposeBlocking()
                exitApplication()
            }
        )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions