afreakyelf / Pdf-Viewer

A Lightweight PDF Viewer Android library which only occupies around 80kb while most of the Pdf viewer occupies up to 16MB space.
https://afreakyelf.github.io/Pdf-Viewer/
MIT License
821 stars 173 forks source link

[BUG] Opening PDF via URL, and then pressing device back button causes app to crash. #100

Closed sumit-joshi28 closed 9 months ago

sumit-joshi28 commented 11 months ago

πŸ“ Describe the Bug

I am loading one PDF URL and while it is in a loading state, I press the device back button. And then reload the same URL and I am getting this crash. I am using Jetpack Compose PdfRendererViewCompose() to load the URL.

FATAL EXCEPTION: main Process: se.ctek.ctekapp, PID: 7596 java.io.IOException: file not in PDF format or corrupted at android.graphics.pdf.PdfRenderer.nativeCreate(Native Method) at android.graphics.pdf.PdfRenderer.<init>(PdfRenderer.java:172) at com.rajat.pdfviewer.PdfRendererCore.openPdfFile(PdfRendererCore.kt:132) at com.rajat.pdfviewer.PdfRendererCore.<init>(PdfRendererCore.kt:48) at com.rajat.pdfviewer.PdfRendererView.init(PdfRendererView.kt:130) at com.rajat.pdfviewer.PdfRendererView.initWithFile(PdfRendererView.kt:101) at com.rajat.pdfviewer.PdfRendererView$initWithUrl$1.onDownloadSuccess(PdfRendererView.kt:90) at com.rajat.pdfviewer.PdfDownloader.checkAndDownload(PdfDownloader.kt:53) at com.rajat.pdfviewer.PdfDownloader.access$checkAndDownload(PdfDownloader.kt:12) at com.rajat.pdfviewer.PdfDownloader$1.invokeSuspend(PdfDownloader.kt:30) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25) at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110) at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56) at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47) at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1) at com.rajat.pdfviewer.PdfDownloader.<init>(PdfDownloader.kt:30) at com.rajat.pdfviewer.PdfRendererView.initWithUrl(PdfRendererView.kt:78)

πŸ“– Library Version

🚢 Steps to Reproduce

Please follow these steps to reproduce the issue:

  1. Open PdfViewer with a URL containing pdf.
  2. Before fully loading immediately navigate to the back screen.
  3. Repeat the step 1, you will find a crash.
github-actions[bot] commented 11 months ago

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.

afreakyelf commented 11 months ago

Hi Do you mind sending me your PDF url, if its not confidential.

sumit-joshi28 commented 11 months ago

This doesn't look like a particular PDF problem, you can check with any large PDF directly loading from the HTTP URL and while it is loading press the back button and load it again, that way you can reproduce the problem.

sumit-joshi28 commented 11 months ago

@afreakyelf Hi, were you able to reproduce the problem?

DarkAbhi commented 10 months ago

+1 , works fine on an higer end device i.e S21, crashes on lower end devices like Asus Zenfone Max Pro M1

Update: now it stopped happening. No code changes.

sumit-joshi28 commented 10 months ago

@DarkAbhi Did you try the exact steps as mentioned?

DarkAbhi commented 10 months ago

@DarkAbhi Did you try the exact steps as mentioned?

Yes.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

afreakyelf commented 9 months ago

Great, thanks @DarkAbhi