Skip to content

fix(pdfx): guard rawDocumentProgress against NaN/Infinity in PdfViewPinch#621

Open
MarkianUchiha wants to merge 1 commit into
ScerIO:mainfrom
MarkianUchiha:fix/pdfx-nan-progress
Open

fix(pdfx): guard rawDocumentProgress against NaN/Infinity in PdfViewPinch#621
MarkianUchiha wants to merge 1 commit into
ScerIO:mainfrom
MarkianUchiha:fix/pdfx-nan-progress

Conversation

@MarkianUchiha

Copy link
Copy Markdown

Problem

PdfViewPinch crashes on Android with:

UnsupportedError: Unsupported operation: Infinity or NaN toInt
  at double.round (dart:core-patch/double.dart:196:34)
  at _PdfViewPinchState._determinePagesToShow
    (package:pdfx/src/viewer/pinch/pdf_view_pinch.dart:299:52)

Reproduced on pdfx 2.9.2, Pixel 10a running Android 15/16/17 (edge-to-edge / gesture nav).

Root cause

In _determinePagesToShow, rawDocumentProgress is computed as:

final rawDocumentProgress =
    ((exposed.bottom / r - _lastViewSize!.height) /
        (_docSize!.height - _lastViewSize!.height));

When the document fits exactly in the viewport (or both dimensions are still 0 during the first frame on Android edge-to-edge), the divisor is 0 → produces NaN/Infinity.round().toInt() throws UnsupportedError and the PDF stays blank.

Fix

Normalize rawDocumentProgress to 0.0 when it is NaN or Infinite before calling .round(). When the document fits the viewport there is no scroll progress to report — 0.0 is the correct semantic value.

var rawDocumentProgress =
    ((exposed.bottom / r - _lastViewSize!.height) /
        (_docSize!.height - _lastViewSize!.height));
if (rawDocumentProgress.isNaN || rawDocumentProgress.isInfinite) {
  rawDocumentProgress = 0.0;
}

Notes

Cuando el documento cabe exactamente en el viewport (o cuando ambos
miden 0 durante el primer frame en Android edge-to-edge / gesture nav),
el divisor (_docSize.height - _lastViewSize.height) es 0 y produce
NaN/Infinity. Al llegar a .round().toInt() lanza UnsupportedError y el
PDF se queda en blanco.

Se normaliza rawDocumentProgress a 0.0 cuando es NaN o Infinite antes
de aplicar .round(): no hay recorrido pendiente si el documento cabe
en pantalla.

Basado en el PR ScerIO#602 de akiller (upstream, sin merge desde nov 2025).
Repro: Pixel 10a Android 15/16, pdfx 2.9.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant