JoanZapata / android-pdfview

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

Problem when continuously loading pdfs #201

Open FranciscoBartilotti opened 8 years ago

FranciscoBartilotti commented 8 years ago

Hi, first of all thank you for your work!

I am using this code to extract a bitmap from the pdf file:

PdfContext pdfc = new PdfContext();
CodecDocument pdfd = pdfc.openDocument(path);
PdfPage pdfp = (PdfPage) pdfd.getPage(0);
Bitmap page = pdfp.renderBitmap(width,height,new RectF(0, 0, 1, 1));

The problem presents consistently when opening 4 pdfs, then trying to open a fifth will crash the app. I am using a Moto G3, Android 6.0 for testing.

Here is the log:

D/PdfDroid: PdfPage.nativeOpenPage(): return handle = 0xb97be768
D/PdfDroid: PdfView(0xa0da126c).nativeCreateView(0xba8e3de0, 0xb97be768)
D/PdfDroid: Matrix: 3.000000 0.000000 0.000000 -3.000000 0.000000 1950.000000
D/PdfDroid: Viewbox: 0 0 1530 1950
D/PdfDroid: doing the rendering...
D/PdfDroid: Converting image buffer pixel order
D/PdfDroid: PdfView.nativeCreateView() done
A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xa0df8000 in tid 26992 (otti.pdfocrdemo)

Also, sometimes the last line changes to: A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xa1c5c000 in tid 30014 (RxIoScheduler-2)

Thank you for any help you can provide!

FranciscoBartilotti commented 8 years ago

Happy to say I found the problem, more than 1 thread was trying to open the document, after revision, everything works as intended.

sarfarazr1406 commented 8 years ago

Hi,

Can you please let me know what changes you made to resolve this issue?

FranciscoBartilotti commented 8 years ago

I am using RxJava, an Observable and Subscription to create a new thread to load the pdf and extract its bitmap. The problem was that more than 1 call could be made to this method, so there could be more than one thread opening the pdf. I added flags to check for this in my code, I changed nothing in the lib. What problem are you experiencing?

sarfarazr1406 commented 8 years ago

Hi, I am opening PDFs in 7 different tabs simultaneously. In first tab it opens properly but in other tabs the app crashes. Please suggest what can I do.

FranciscoBartilotti commented 8 years ago

It seems it is not possible to load various pdfs without changing the native code because each time it loads the lib,

D/PdfDroid: initializing PdfRender JNI library based on MuPDF
D/PdfDroid: PdfDocument.nativeOpen(): return handle = 0xb991f238

I suggest you call one, wait for it to load, then proceed with the next.

pramodpmk commented 7 years ago

I'm using this library to load multiple pdf files back to back in same fragment. My fragment has a pdf view , next and previous buttons to switch between pdf files. I'm facing app crash when loading files back to back. Nothing changes even i give it some time say two three seconds after loading each file. Still crashes. Included library via gradle (version 1.0.4). I'm modifying an old work, can anyone suggest a resolution for the issue?

Here attaching my stack trace crash

pramodpmk commented 7 years ago

GET RID OF THE ISSUE FOR MY USE CASE Added a delay of 2sec before calling new pdf load using handler().postDelayed. Simple but saved the day