Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash: Double value cannot be converted to Int because the result would be less than Int.min #2249

Open
davicorpedev opened this issue Jan 8, 2025 · 1 comment
Labels
follow-up scheduled Follow-up scheduled pdf viewer PDF viewer component

Comments

@davicorpedev
Copy link

Bug description

We are encountering an issue with the latest release of the following packages:

  • syncfusion_flutter_pdf (version: 28.1.33)
  • syncfusion_flutter_pdfviewer (version: 28.1.33)

The problem occurs when generating PDFs on demand. Specifically, it arises when we modify the text content of the PDF document. Each time the text is updated, the application crashes.

We are uncertain of the exact cause, but it seems to be realted to _extractText function. When debugging with breakpoints set in this function, the issue disappears, and the crash no longer occurs.

The issue also shows an error on SwiftSyncfusionFlutterPdfViewerPlugin.getTileImageForPlugin

Steps to reproduce

  1. Generate a PDF and save the bytes using the package:pdf/pdf.dart.
  2. Display the generated bytes using SfPdfViewer.memory.
  3. Regenerate the PDF, modifying the text content of the document.
  4. Observe: The application crashes.

Code sample

Code sample
  return SfPdfViewerTheme(
        data: pdfViewerThemeData,
        child: SfPdfViewer.memory(
          widget.bytes!,
          controller: widget.controller,
          canShowPaginationDialog: false,
          canShowPasswordDialog: false,
          canShowScrollHead: false,
          canShowScrollStatus: false,
          canShowPageLoadingIndicator: false,
          canShowHyperlinkDialog: false,
          pageLayoutMode: kIsWeb ? PdfPageLayoutMode.continuous : PdfPageLayoutMode.single,
          scrollDirection: kIsWeb ? PdfScrollDirection.vertical : PdfScrollDirection.horizontal,
          initialZoomLevel: widget.initialZoomLevel,
          maxZoomLevel: kZoomMax,
          onHyperlinkClicked: (details) {
            launchUrlInBrowser(url: details.uri, webOnlyWindowName: '_self');
          },
          onTextSelectionChanged: _onTextSelectionChanged,
        ),
      );

Screenshots or Video

Screenshots / Video demonstration

Screenshot 2025-01-08 at 14 54 35

Stack Traces

Stack Traces
* thread #55, queue = 'syncfusion_flutter_pdfviewer', stop reason = Swift runtime failure: Double value cannot be converted to Int because the result would be less than Int.min
    frame #1: 0x00000001033d649c syncfusion_flutter_pdfviewer`SwiftSyncfusionFlutterPdfViewerPlugin.getTileImageForPlugin(pageNumber=<unavailable>, scale=<unavailable>, width=NaN, height=NaN, x=NaN, y=<unavailable>, documentID="1ce0e290-cdcb-11ef-b80b-3fb4f322863c") at SwiftSyncfusionFlutterPdfViewerPlugin.swift:206:22 [opt]
   203 	                            y: -(pageHeight * scale / 2) + (pageHeight / 2) + CGFloat(y),
   204 	                            width: pageWidth * scale, height: pageHeight * scale)
   205 	        
-> 206 	        let stride = Int(width) * 4
    	                     ^
   207 	        let bufSize = stride * Int(height);
   208 	        let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufSize)
   209 	        buffer.initialize(repeating:  0, count: bufSize)
Target 0: (Runner) stopped.
warning: syncfusion_flutter_pdfviewer was compiled with optimization - stepping may behave oddly; variables may not be available.

On which target platforms have you observed this bug?

iOS

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.7 23H124 darwin-arm64, locale en-ES)
    • Flutter version 3.24.3 on channel stable at /Users/david/fvm/versions/3.24.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (4 months ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/david/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (4 available)
    • iPhone de David (mobile)        • 00008030-00126158369A802E • ios            • iOS 16.7 20H19
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.7 23H124 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.7 23H124 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 131.0.6778.264
 

[✓] Network resources
    • All expected network resources are available.
@VijayakumarMariappan VijayakumarMariappan added pdf viewer PDF viewer component open Open labels Jan 9, 2025
@Deepak1799
Copy link
Collaborator

@davicorpedev We are able to replicate the reported issue, where the application crashes in single-page layout mode, when loading a PDF document which is created by adding text using the syncfusion_flutter_pdf library in the syncfusion_flutter_pdfviewer. We are currently validating this issue and will provide further updates once we identify the root cause.

@Deepak1799 Deepak1799 added follow-up scheduled Follow-up scheduled and removed open Open labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
follow-up scheduled Follow-up scheduled pdf viewer PDF viewer component
Projects
None yet
Development

No branches or pull requests

3 participants