espresso3389 / pdfrx

pdfrx is yet another PDF viewer implementation that built on the top of pdfium. The plugin currently supports Android, iOS, Windows, macOS, Linux, and Web.
MIT License
60 stars 36 forks source link

EXC_BAD_ACCESS using PdfPageView on iOS devices #108

Open KevinHaendel opened 1 month ago

KevinHaendel commented 1 month ago

Hi!

We use PdfDocumentViewBuilder.file() around a PhotoViewGallery-Widget (of the https://pub.dev/packages/photo_view package, which is not part of the subject) to load a PdfDocument. To show the pages in the PhotoViewGallery, we use PdfPageView for each page with a custom pageSizeCallback determining a good looking render size calculated by the device dimensions and the current zoom level. When a user zooms in, the pageSizeCallback will be replaced with a new method returning a new size of the page view. All in all this method works like a charm.

However, sometimes when rendering the PdfPageView, we sometimes encounter errors on iOS, especially on iPads. Here's a screenshot of our Sentry environment capturing the error:

image

Could be the pointer-issue that we replace the PdfPageView too often when a user zooms in and out, which results in multiple replacements of the pageSizeCallback function? If so, is there any way to stop rendering the current page and replace the render process by a new one?

espresso3389 commented 1 month ago

Ah, there seems memory allocation failures on the native code :( The PdfPagePdfium.render code actually lacks checking of memory allocation error but the ultimate cause of the issue is memory shortage (out of memory).

What we should do is to limit the maximum size of the image rendered on these devices.