Skip to content

[BUG] When I show or hide a using a condition, the app may crash if the PdfRendererViewCompose has not finished rendering its pageΒ #220

@TxcA

Description

@TxcA

πŸ“ Describe the Bug

I’m using Jetpack Compose. When I show or hide a PdfRendererViewCompose using a if condition, the app may crash if the PdfRendererViewCompose has not finished rendering its page β€” for example, if the PDF is still loading or the user is switching to the next page and rendering is in progress.

The crash does not provide a detailed stack trace. The only output in logcat is:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x70 in tid 13729 (DefaultDispatch), pid 13679 (x)

πŸ“– Library Version

2.3.7

🚢 Steps to Reproduce

Please follow these steps to reproduce the issue:

  1. Display a PdfRendererViewCompose in a Compose screen.
  2. Start loading a PDF or scroll to switch pages.
  3. While rendering is in progress, trigger the if condition to remove or hide the PdfRendererViewCompose.

πŸ€” Expected Behavior

Confirm if my usage issue is still the current problem with PdfViewer

πŸ’» Code Snippets

        if (showPdf && viewModel.pdfFile != null) {
            var loadingPdf by remember { mutableStateOf(true) }

            Box(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color(0xCC222222)),
                contentAlignment = Alignment.BottomCenter
            ) {

                Box(
                    modifier = Modifier
                        .padding(36.dp)
                        .size(64.dp)
                        .clip(CircleShape)
                        .background(Color(0x80FFFFFF))
                        .align(Alignment.TopStart)
                        .clickable {
                            showPdf = false
                            viewModel.pdfFile = null
                        }
                ) {
                    Icon(
                        imageVector = Icons.Default.Close,
                        contentDescription = null,
                        tint = Color.White,
                        modifier = Modifier
                            .fillMaxSize()
                            .padding(12.dp)
                    )
                }

                Box(
                    modifier = Modifier
                        .fillMaxHeight()
                        .aspectRatio(0.75f)
                ) {
                    if (loadingPdf) {
                        CircularProgressIndicator(
                            color = Color.White, modifier = Modifier
                                .size(128.dp)
                                .align(Alignment.Center)
                        )
                    }

                    PdfRendererViewCompose(
                        source = PdfSource.LocalFile(viewModel.pdfFile!!.file),
                        lifecycleOwner = LocalLifecycleOwner.current,
                        cacheStrategy = CacheStrategy.DISABLE_CACHE,
                        statusCallBack = object : PdfRendererView.StatusCallBack {
                            override fun onPdfLoadStart() {
                                Log.d("xxxPDF", "onPdfLoadStart")
                            }

                            override fun onPdfLoadProgress(progress: Int, downloadedBytes: Long, totalBytes: Long?) {
                                Log.d("xxxPDF", "onPdfLoadProgress: progress= ${progress}, downloadedBytes= ${downloadedBytes}, totalBytes= $totalBytes")
                            }

                            override fun onPdfLoadSuccess(absolutePath: String) {
                                Log.d("xxxPDF", "onPdfLoadSuccess: absolutePath= $absolutePath")
                            }

                            override fun onError(error: Throwable) {
                                Log.d("xxxPDF", "onError: error= ${error.stackTraceToString()}")
                            }

                            override fun onPageChanged(currentPage: Int, totalPage: Int) {
                                Log.d("xxxPDF", "onPageChanged: currentPage= ${currentPage}, totalPage= $totalPage")
                            }

                            override fun onPdfRenderStart() {
                                Log.d("xxxPDF", "onPdfRenderStart")
                            }

                            override fun onPdfRenderSuccess() {
                                Log.d("xxxPDF", "onPdfRenderSuccess")
                            }
                        },
                        modifier = Modifier.fillMaxSize()
                    )
                }
            }
        }

πŸ“œ Log Output/Stack Trace

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x70 in tid 13729 (DefaultDispatch), pid 13679 (x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions