Closed zengchanghuan closed 1 month ago
This is my code:
PdfViewer.asset(
'assets/hello.pdf',
passwordProvider: () => passwordDialog(context),
controller: controller,
params: PdfViewerParams(
enableTextSelection: true,
maxScale: 8,
),
),
My hello.pdf have 47 pages.
There seems some problem on analyzing text data on the PDF. Could you provide me with the PDF? Or do you have any other public PDF file that also exhibits the same issue?
And, also, please provide flutter doctor -v
.
This is the crash log.
flutter --version Flutter 3.19.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7482962148 (2 weeks ago) • 2024-02-27 16:51:22 -0500 Engine • revision 04817c99c9 Tools • Dart 3.3.0 • DevTools 2.31.1
flutter doctor -v [✓] Flutter (Channel stable, 3.19.2, on macOS 13.5.1 22G90 darwin-arm64, locale zh-Hans-CN) • Flutter version 3.19.2 on channel stable at /Users/zengchanghuan/Documents/dev_flutter/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7482962148 (2 weeks ago), 2024-02-27 16:51:22 -0500 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/zengchanghuan/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.6+0-17.0.6b829.9-10027231) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.14.3
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3) • 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.6+0-17.0.6b829.9-10027231)
[✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.84.0
[!] Proxy Configuration • HTTP_PROXY is set ! NO_PROXY is not set
[✓] Connected device (3 available) • BON AL00 (mobile) • 2LP9K24106000912 • android-arm64 • Android 12 (API 31) • macOS (desktop) • macos • darwin-arm64 • macOS 13.5.1 22G90 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 122.0.6261.129
[✓] Network resources • All expected network resources are available.
! Doctor found issues in 1 category.
I'm testing the issue but I'm not sure why so many RangeError caused on your environment. I could not reproduce your issue...
This problem can be reproduced by quickly sliding the file。
At some zoom ratio (zoom-upped), I reproduces the issue.
And under profiling mode, it seems RSS memory gets 800MB+ and I suspect that the RSS is the actual cause of the issue. But I don't know how to fix it so far...
@zengchanghuan 1.0.52 fixes certain memory leaks and related issues. Please check it.
======== Exception caught by rendering library =====================================================
The following assertion was thrown during paint():
'dart:ui/painting.dart': Failed assertion: line 6025 pos 12: '<optimized out>': is not true.
The relevant error-causing widget was:
CustomPaint CustomPaint:file:///Users/zengchanghuan/Desktop/workspace/github_demo/pdfrx/lib/src/widgets/pdf_viewer.dart:413:30
When the exception was thrown, this was the stack:
#2 _NativeCanvas.drawImageRect (dart:ui/painting.dart:6025:12)
#3 _PdfViewerState._customPaint (package:pdfrx/src/widgets/pdf_viewer.dart:797:16)
#4 _CustomPainter.paint (package:pdfrx/src/widgets/pdf_viewer.dart:1660:62)
#5 RenderCustomPaint._paintWithPainter (package:flutter/src/rendering/custom_paint.dart:588:13)
#6 RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:635:7)
#7 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#8 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#9 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#10 PaintingContext.pushTransform (package:flutter/src/rendering/object.dart:687:14)
#11 RenderTransform.paint (package:flutter/src/rendering/proxy_box.dart:2541:27)
#12 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#13 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#14 RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:74:15)
#15 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#16 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#17 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#18 PaintingContext.pushClipRect.<anonymous closure> (package:flutter/src/rendering/object.dart:549:83)
#19 ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:25:12)
#20 ClipContext.clipRectAndPaint (package:flutter/src/painting/clip.dart:53:5)
#21 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:549:7)
#22 RenderClipRect.paint (package:flutter/src/rendering/proxy_box.dart:1538:25)
#23 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#24 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#25 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#26 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#27 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#28 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#29 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#30 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#31 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#32 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#33 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#34 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2882:15)
#35 RenderStack.paintStack (package:flutter/src/rendering/stack.dart:641:5)
#36 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:486:12)
#37 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:546:7)
#38 RenderStack.paint (package:flutter/src/rendering/stack.dart:647:38)
#39 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#40 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#41 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#42 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#43 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#44 _RenderColoredBox.paint (package:flutter/src/widgets/basic.dart:7829:15)
#45 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#46 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#47 _RenderLayoutBuilder.paint (package:flutter/src/widgets/layout_builder.dart:356:15)
#48 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#49 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#50 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2882:15)
#51 RenderStack.paintStack (package:flutter/src/rendering/stack.dart:641:5)
#52 RenderStack.paint (package:flutter/src/rendering/stack.dart:657:7)
#53 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#54 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#55 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2882:15)
#56 RenderFlex.paint (package:flutter/src/rendering/flex.dart:1041:7)
#57 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#58 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#59 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2882:15)
#60 RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:409:5)
#61 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#62 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#63 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#64 _RenderInkFeatures.paint (package:flutter/src/material/material.dart:662:11)
#65 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#66 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#67 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#68 RenderPhysicalModel.paint.<anonymous closure> (package:flutter/src/rendering/proxy_box.dart:2049:15)
#69 PaintingContext.pushClipRRect (package:flutter/src/rendering/object.dart:575:14)
#70 RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:2036:21)
#71 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#72 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#73 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#74 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#75 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:250:13)
#76 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:130:13)
#77 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3237:7)
#78 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:166:11)
#79 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:109:5)
#80 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:1182:31)
#81 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:1192:15)
#82 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:584:23)
#83 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:991:13)
#84 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
#85 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
#86 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
#87 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1169:5)
#88 _invoke (dart:ui/hooks.dart:312:13)
#89 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:399:5)
#90 _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
The following RenderObject was being processed when the exception was fired: RenderCustomPaint#79e6b relayoutBoundary=up2
... parentData: <none> (can use size)
... constraints: BoxConstraints(unconstrained)
... size: Size(1433.4, 37687.0)
... painter: null
... foregroundPainter: _CustomPainter#4d0d3()
... preferredSize: Size(1433.4, 37687.0)
RenderObject: RenderCustomPaint#79e6b relayoutBoundary=up2
parentData: <none> (can use size)
constraints: BoxConstraints(unconstrained)
size: Size(1433.4, 37687.0)
painter: null
foregroundPainter: _CustomPainter#4d0d3()
preferredSize: Size(1433.4, 37687.0)
====================================================================================================
Lost connection to device.
the Dart compiler exited unexpectedly.
@zengchanghuan Please quote your stacktrace with ```. It's too large.
The exception causes some flicker on user operation and I've found the actual casue. I'm now working on a fix, that is related to #121 and #122. Please wait a little more.
@zengchanghuan Please quote your stacktrace with ```. It's too large.
The exception causes some flicker on user operation and I've found the actual casue. I'm now working on a fix, that is related to #121 and #122. Please wait a little more.
I also found a deeper cause for the RSS exploding issue. It's FPDF_RenderPageBitmap
. When we render something with it, this little one puts a lot into the page's cache but never release it until we call FPDF_ClosePage
. Perhaps we should only FPDF_LoadPage
for any rendering job and then FPDF_ClosePage
right away?
I also notice there is a FPDF_ClearPageCaches
function somewhere in pdfium, not sure if we could use it though.
I also found a deeper cause for the RSS exploding issue. It's FPDF_RenderPageBitmap. When we render something with it, this little one puts a lot into the page's cache but never release it until we call FPDF_ClosePage
I know that. But I think it's relatively small. Do you think it impacts the memory usage?
I'm not sure which is better (for any/certain kind of efficiency) to open/close page instance every timeor keep the handle on memory.
In my experience, you can provide a method to release memory, and it is up to the developer to decide whether to actively release memory when closing the page.
I also found a deeper cause for the RSS exploding issue. It's FPDF_RenderPageBitmap. When we render something with it, this little one puts a lot into the page's cache but never release it until we call FPDF_ClosePage
I know that. But I think it's relatively small. Do you think it impacts the memory usage?
I'm not sure which is better (for any/certain kind of efficiency) to open/close page instance every timeor keep the handle on memory.
Yep, the first run with FPDF_RenderPageBitmap for a 4000x3000 page increases memory usage by 500mb, and it never releases it. If the page has the same lifetime as PdfDocumentPdfium, it is just too large to keep in memory and for too long..
Anyway, 1.0.53 fixes the flicker that was introduced by the previous version.
For FPDF_RenderPageBitmap memory issue, if you really need such function, please create another issue.