ScerIO / packages.flutter

👨‍💻 Plugins and packages for Flutter framework
https://pub.dev/publishers/serge.software/packages
MIT License
456 stars 449 forks source link

Crashes on Web after 80-100 individual page renders #333

Open timovandeput opened 2 years ago

timovandeput commented 2 years ago

Describe the bug The browser page crashes after opening a PDF and rendering a single page some 100 times.

To Reproduce This code consistently crashes between iteration 80 and 100 on my MacBook Pro for a (mixed text and image) file of 150k bytes:

  Future<void> render(int times) async {
    for (var i = 1; i <= times; i++) {
      try {
        print('Rendering $i');
        final document = await PdfDocument.openData(_fileBuffer!);
        final page = await document.getPage(1);
        await page.render(width: page.width, height: page.height);
        await page.close();
        await document.close();
      } catch (e) {
        print('Exception on render $i: $e');
      }
    }
  }

Expected behaviour Render infinitely without crashing :-)

Environment

Additional context (none)

timovandeput commented 2 years ago

It looks the problem is caused by a resource leak in opening / closing the PDF document, as rendering many pages without closing and reopening the document does work.