Pdf-Viewer icon indicating copy to clipboard operation
Pdf-Viewer copied to clipboard

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

Open TxcA opened this issue 6 months ago • 2 comments

šŸ“ 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)

TxcA avatar Jul 11 '25 09:07 TxcA

Thank you for creating your first issue. We appreciate your help in making this project better. We will look into it, and get back to you soon. Need help or want to discuss this issue? Join our Discord community here to ask questions and discuss this issue live!

github-actions[bot] avatar Jul 11 '25 09:07 github-actions[bot]

Have the same issue, same stack trace:

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

AdminCarlos avatar Jul 18 '25 01:07 AdminCarlos