JoanZapata / android-pdfview

[DEPRECATED] A fast PDF reader component for Android development
http://joanzapata.com/android-pdfview/
GNU General Public License v3.0
2.83k stars 785 forks source link

Thread safety issue #50

Open JoanZapata opened 10 years ago

JoanZapata commented 10 years ago

See #46

I ran into a regular crash when i was using the component to display various pdf file : on the left pane the name of the file and when the user click on a name, the pdf is displayed on the right. Switching quickly between files to display led me into a RunTimeException in the function :

static PdfPage createPage(long dochandle, int pageno){
return new PdfPage(open(dochandle, pageno), dochandle);
}

in org.vudroid.pdfdroid.codec.PdfPage. A little investigation led me to find that this happened when two threads was calling this function at the same time.

Kresshy commented 9 years ago

Hi,

I have a similar problem. After the pdf loaded and seems to be fully rendered (while or after the rendering) the application crashes.

java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:304)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
 Caused by: java.lang.RuntimeException: error loading page
        at org.vudroid.pdfdroid.codec.PdfPage.open(Native Method)
        at org.vudroid.pdfdroid.codec.PdfPage.createPage(PdfPage.java:55)
        at org.vudroid.pdfdroid.codec.PdfDocument.getPage(PdfDocument.java:18)
        at org.vudroid.core.DecodeServiceBase.getPage(DecodeServiceBase.java:175)
        at com.joanzapata.pdfview.RenderingAsyncTask.proceed(RenderingAsyncTask.java:100)
        at com.joanzapata.pdfview.RenderingAsyncTask.doInBackground(RenderingAsyncTask.java:63)
        at com.joanzapata.pdfview.RenderingAsyncTask.doInBackground(RenderingAsyncTask.java:33)
        at android.os.AsyncTask$2.call(AsyncTask.java:292)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)

This happens only for a few pdf files. I can send you these to reproduce the issue if you wish.

JoanZapata commented 9 years ago

This error comes from the underlying library so there's no way I can fix it. An issue is currently opened to at least be able to catch those exceptions. See #29

Kresshy commented 9 years ago

Thanks for the answer :)