zathras / jovial_svg

Flutter library for robust, efficient rendering of SVG static images
BSD 3-Clause "New" or "Revised" License
100 stars 20 forks source link

Possible bug in Flutter's PictureRecorder API #96

Closed sgehrman closed 4 months ago

sgehrman commented 4 months ago

https://docs.gtk.org/gtk3/gtk-logo.svg

I was trying this:


  Future<Uint8List> _renderToBytes(
      {required ImageByteFormat format, Size? scaleTo}) async {
    final si = await ScalableImage.fromSvgHttpUrl(
        Uri.parse('https://docs.gtk.org/gtk3/gtk-logo.svg'));

    await si.prepareImages();
    final vpSize = si.viewport;
    final recorder = PictureRecorder();
    final Canvas c = Canvas(recorder);
    if (scaleTo != null) {
      c.scale(scaleTo.width / vpSize.width, scaleTo.height / vpSize.height);
    }
    si.paint(c);
    si.unprepareImages();
    final size = scaleTo ?? Size(vpSize.width, vpSize.height);

    final Picture pict = recorder.endRecording();
    final rendered =
        await pict.toImage(size.width.round(), size.height.round());

    final ByteData? bd = await rendered.toByteData(format: format);
    final r = Uint8List.fromList(bd!.buffer.asUint8List());

    rendered.dispose();
    pict.dispose();

    return r;
  }

toImage bombs.

zathras commented 4 months ago

Picture is not part of jovial_svg. You didn't give a full, reproducible example (or the exact error message with stack backtrace), but I assume you mean Flutter's Picture class. That's where you need to submit the bug.

sgehrman commented 4 months ago

maybe your corrupting memory? I tried removing the unprepareImages and it seemed to work bettter.

zathras commented 4 months ago

Given that there's no native code in jovial_svg, no. BTW, I did check using the demo program, and that SVG renders fine.

You really do need to file the bug against the library where the crash is occurring. When you do, I'd suggest providing more information, like what exactly you mean by "crash," what exact error you get, what platform you're on, backtrace (assuming there is one), etc. Saying vague things like "seemed to work better" isn't much help.

sgehrman commented 4 months ago

flutter_svg crashes too. (app just exits, no logs, no nothing)

Yes the svg seems to render fine, but drawing into a canvas and the toImage crashes?

I'm banned from the flutter github. Could you post this bug?

sgehrman commented 4 months ago

It seems it only crashes in flutter 3.22. It would be helpful if you could report this. thanks.

zathras commented 4 months ago

I'm banned from the flutter github. Could you post this bug?

I could do that, if you'd submit a complete, reproducible bug report. That would include a short, stand-alone program that reproduces the problem (and not just a program snippet -- include something that can be actually be built, e.g. with the imports), and include all the standard stuff for this kind of bug report, like your platform, the output of "flutter doctor -v", etc. Take a look at the flutter bug submission guidelines to see the sort of things that need to be include. So far, you haven't even said what platform you're on.

You should also include everything you know. Like, what do you mean it "works better?" Do you mean it works? In English, "works better" means that there are still problems. What, exactly? Or are you just being imprecise?

As a general rule, try to be polite, give complete and clear information. Don't say "bombs" - that could mean any of a dozen things. Say what actually happens. And don't leave out important information, like the fact that you have the same problem with flutter_svg. Generally speaking, do some work yourself before firing off a bug -- especially when the bug comes up when you call an API that isn't even in the package you're submitting against!

You're asking for a favor. Don't make the person you're asking the favor from do a bunch of guesswork.

sgehrman commented 4 months ago

https://github.com/sgehrman/to_image_bug

see readme for info.

Thanks.

If you happen to know someone at Google, ask them to unban me. I have no contacts there so I'm not able to ask myself.

sgehrman commented 4 months ago

https://github.com/SachinGanesh/screenshot/issues/185

@zathras could you post this info on the flutter bug? I reproduced it using 'screenshot' with the border radius issue @azkadev mentioned. I want to get this resolved quickly. thanks.