syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.46k stars 680 forks source link

The app crashes when opening and closing the PDF view screen multiple times rapidly. This issue is observed with the syncfusion_flutter_pdfviewer. #1739

Open sahal01 opened 2 months ago

sahal01 commented 2 months ago

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Current page not closed, null, java.lang.IllegalStateException: Current page not closed at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:273) at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:186) at h6.c.a(Unknown Source:13) at h6.c.e(Unknown Source:83) at e7.k$a.a(Unknown Source:17) at r6.c.l(Unknown Source:18) at r6.c.m(Unknown Source:40) at r6.c.i(Unknown Source:0) at r6.b.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) ) at StandardMethodCodec.decodeEnvelope(message_codecs.dart:652) at MethodChannel._invokeMethod(platform_channel.dart:310) at PdfViewerPlugin.closeDocument(pdfviewer_plugin.dart:154)

immankumarsync commented 2 months ago

Hi @sahal01,

We tried to replicate the reported issue, and we didn't face any issues related to the specified stack trace. Please find the sample that we used to replicate the issue and the screen recording in the attachments. If the issue still occurs on your end, kindly share with us a simple sample in which the issue replicates and the replication steps or replication video. This will help us provide a prompt solution at the earliest. 

Sample.zip

sahal01 commented 2 months ago

syncfusion_flutter_pdfviewer/SwiftSyncfusionFlutterPdfViewerPlugin.swift:136: Fatal error: Unexpectedly found nil while unwrapping an Optional value Lost connection to device. Exception: Unable to terminate ProcessException: Process exited abnormally: An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=3): Simulator device failed to terminate found nothing to terminate

The iOS app is experiencing crashes, while the Android app is not crashing. However, Crashlytics reports errors as mentioned above. I am downloading a file and storing it in the app cache, and then using that path to display the PDF.

here is the code :

final file = File(tempPath.toString());

                      if (file.existsSync()) {

                        return SfPdfViewer.file(
                          file,
                          scrollDirection:
                          PdfScrollDirection.horizontal,
                          canShowScrollHead: false,
                          canShowScrollStatus: false,
                          pageSpacing: 3,maxZoomLevel: 8,
                          controller: pdfViewerController,
                        );
                      } else {
                        /// Handle the case where the file doesn't exist
                        return Container();
                      }

using syncfusion_flutter_pdfviewer 23.1.40

immankumarsync commented 2 months ago

@sahal01, we have already resolved this issue in version 24.2.5. Could you please check with version 24.2.5 or later, and check whether the issue is resolved?

sahal01 commented 2 months ago

@immankumarsync Again Crashing in same scenario:

Lost connection to device. Error: Unable to terminate com.test on 3305A-93BF-4E42-B5A5-D49358: ProcessException: Process exited abnormally with exit code 3: An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=3): Simulator device failed to terminate com.test. found nothing to terminate Underlying error (domain=NSPOSIXErrorDomain, code=3): The request to terminate "com.test" failed. found nothing to terminate found nothing to terminate Command: /usr/bin/arch -arm64e xcrun simctl terminate 33B2305A-93BF-4E42-B5A5-C74719D49358 com.test the Dart compiler exited unexpectedly.

updated to : syncfusion_flutter_pdfviewer 24.2.8

immankumarsync commented 2 months ago

@sahal01, we have checked the reported case with the sample we shared previously on the iOS platform, and we are unable to replicate the reported issue. Please find the screen recording from the attachments. Kindy share the below details to analyze the issue further and provide a prompt solution,

  1. A simple sample in which the issue replicates
  2. Complete stack trace
  3. Replication video/steps

https://github.com/syncfusion/flutter-widgets/assets/93641486/4d5a7512-efe3-4b42-b2b9-e64b0833fc86

sahal01 commented 2 months ago

@immankumarsync When dealing with large PDF files, the app crashes while continuously selecting different PDFs. These PDFs are initially stored as mentioned above in the cache, and their paths are used to display the PDFs.

final file = File(tempPath.toString());

                  if (file.existsSync()) {

                    return SfPdfViewer.file(
                      file,
                      scrollDirection:
                      PdfScrollDirection.horizontal,
                      canShowScrollHead: false,
                      canShowScrollStatus: false,
                      pageSpacing: 3,maxZoomLevel: 8,
                      controller: pdfViewerController,
                    );
                  } else {
                    /// Handle the case where the file doesn't exist
                    return Container();
                  }

Lost connection to device. Error: Unable to terminate com.example.pdfviewerApp on 33B2305A-93BF-4E42-B5A5-C74719D49358: ProcessException: Process exited abnormally with exit code -2:

Command: /usr/bin/arch -arm64e xcrun simctl terminate 33B2305A-93BF-4E42-B5A5-C74719D49358 com.example.pdfviewerApp the Dart compiler exited unexpectedly.

Here is the example : https://we.tl/t-37OWUPug8q

immankumarsync commented 2 months ago

@sahal01, we suspect that the application is crashing due to the high memory usage when extracting the text content from the document and on closing the document the memory is not cleared properly. We have already logged a bug report for this issue, and the fix will be included in the April 2, 2024, weekly release.

sahal01 commented 2 months ago

immankumarsync

Noted With Thanks.

immankumarsync commented 2 months ago

Hi @sahal01,

We have resolved the "High memory consumption when loading and unloading the large and high-resolution documents frequently" issue, and the fix for the same is available in our latest weekly release.

Please find the package link, syncfusion_flutter_pdfviewer v25.1.38

Root cause: We extract all the text in the PDF document in an isolate once the document is loaded in the SfPdfViewer widget. On unloading the document, the resources used by the isolate were not cleared completely. Thus holding up the memory usage for every document loaded. Now, we have cleared all the resources used for text extraction if we unload the document before the text extraction completes.

Note: For PDF documents with a lot of text and image contents, depending on the page count, the text extraction process utilizes high memory.

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

sahal01 commented 1 month ago

@ramkumarsync Again same issue occurs app crashing while opening multiple times different pdfs

showing :

Lost connection to device. the Dart compiler exited unexpectedly. Error: Unable to terminate com.example on 8A5032249060-3776-4DA8-4334-AF123434300370: ProcessException: Process exited abnormally with exit code 3: An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=3):

sahal01 commented 1 month ago

@ramkumarsync Any Updates?

immankumarsync commented 1 month ago

@sahal, we tried to replicate the reported issue by repeatedly loading the PDF documents with large text and image contents, and the PDF documents were loaded properly, and we faced no app crashes. If you feel that the SfPdfViewer widget is using more memory, please share with us a replication video along with the Dart Dev Tools memory page.

sahal commented 1 month ago

@sahal, we tried to replicate the reported issue by repeatedly loading the PDF documents with large text and image contents, and the PDF documents were loaded properly, and we faced no app crashes. If you feel that the SfPdfViewer widget is using more memory, please share with us a replication video along with the Dart Dev Tools memory page.

I think you might've tagged the wrong person here.

FYI, @sahal01

Hope this works out for y'all.