packages.flutter icon indicating copy to clipboard operation
packages.flutter copied to clipboard

[native_pdf_view] Fatal error on MacOS

Open spikelucky opened this issue 3 years ago • 10 comments

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file native_pdf_renderer/NativePdfRendererPlugin.swift, line 60 Lost connection to device.

I'm using native_pdf_view I've been using the same code for a web app and it worked fine, but on MacOS I get the error. It seems to be crashing while initialising the PdfController.

spikelucky avatar Oct 06 '21 13:10 spikelucky

Please retry with last version [native_pdf_view] v5.0.0

SergeShkurko avatar Oct 23 '21 23:10 SergeShkurko

I still get the error on MacOS: Fatal error: Unexpectedly found nil while unwrapping an Optional value: file native_pdf_renderer/NativePdfRendererPlugin.swift, line 60 Lost connection to device.

I'll try it on Windows as soon as I get a chance to get on a windows pc.

spikelucky avatar Oct 25 '21 19:10 spikelucky

I still get the error on MacOS: Fatal error: Unexpectedly found nil while unwrapping an Optional value: file

i cant reproduce bug on macOS Which version of flutter and nacOS you usage? What time What do you do at the time of departure? Can you attach a pdf file with which your application crashes? what additional arguments are you using?

SergeShkurko avatar Oct 25 '21 23:10 SergeShkurko

If you use renderer:

renderer: (PdfPage page) => page.render(
  width: page.width * 2,
  height: page.height * 2,

  format: PdfPageFormat.WEBP, <--

  backgroundColor: '#FFFFFF',
),

MacOs does not support PdfPageFormat.WEBP when i try usage it i handle same error: image

Try specify PdfPageFormat.JPEG

SergeShkurko avatar Oct 25 '21 23:10 SergeShkurko

I tried on both the stable and dev flutter channels. I'll try that direct edit in the renderer next, not sure how to do this though.

spikelucky avatar Oct 27 '21 18:10 spikelucky

it already looked like this:

/// Default PdfRenderer options static Future<PdfPageImage?> _render(PdfPage page) => page.render( width: page.width * 2, height: page.height * 2, format: PdfPageFormat.JPEG, backgroundColor: '#ffffff', );

spikelucky avatar Oct 27 '21 18:10 spikelucky

Also this catch is in the renderer code: async { if (format == PdfPageFormat.WEBP && (UniversalPlatform.isIOS || UniversalPlatform.isWindows)) { throw PdfNotSupportException( 'PDF Renderer on IOS & Windows platforms do not support WEBP format', ); }

but is error isn't being invoked

spikelucky avatar Oct 27 '21 18:10 spikelucky

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file native_pdf_renderer/NativePdfRendererPlugin.swift, line 60 Lost connection to device. Exited (sigterm)

Looking at the file and line mentioned in the error the line reads: result(documents.register(renderer: renderer!).infoMap as NSDictionary)

the whole function:

func openDocumentAssetHandler(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void {
    guard let name = call.arguments as! String? else {
        return result(FlutterError(code: "RENDER_ERROR",
                                   message: "Arguments not sended",
                                   details: nil))
    }
    let renderer = openAssetDocument(name: name)
    result(documents.register(renderer: renderer!).infoMap as NSDictionary)
}

I wonder if that nullcheck (renderer!) for some reason returns nil here

spikelucky avatar Oct 27 '21 19:10 spikelucky

Problem throws after run builded release (flutter build, then run) or on local dev run (flutter run) ?

SergeShkurko avatar Nov 03 '21 20:11 SergeShkurko

Has this been resolved? I just ran into this same error ...

mprogers avatar Feb 03 '22 03:02 mprogers