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

Error when switching to homescreen during capture #11

Open
michelesandroni opened this issue Apr 1, 2023 · 6 comments
Open

Error when switching to homescreen during capture #11

michelesandroni opened this issue Apr 1, 2023 · 6 comments
Labels
bug Something isn't working discussion help wanted Extra attention is needed render capturing issues that involve capturing of frames

Comments

@michelesandroni
Copy link

When switching to the home screen while using captureMotionWithStream() an exception is thrown:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value #0 _Image.toByteData.<anonymous closure>.<anonymous closure> (dart:ui/painting.dart:1891:25)

Expected behavior: The rendering / capture process should be paused?

The exception refers to line 1891 of painting.dart

  Future<ByteData?> toByteData({ImageByteFormat format = ImageByteFormat.rawRgba}) {
    return _futurize((_Callback<ByteData> callback) {
      return _toByteData(format.index, (Uint8List? encoded) {
        callback(encoded!.buffer.asByteData()); // <------------------- this line
      });
    });
  }

Any ideas or workarounds on how to avoid this would be great!
Thanks a lot.

@michelesandroni michelesandroni added the bug Something isn't working label Apr 1, 2023
@polarby
Copy link
Owner

polarby commented Apr 1, 2023

Interesting bug! Thanks for opening the issue.

This is quite a difficult problem, as RAM images might be deleted when other applications also require RAM. Rather than pausing stopping the capturing process seems to be more appropriate. But even then, the written images are still in the RAM and converting & processing might take a while. During this time the user might open other applications or occupy RAM in another way (and I think ios even forbids heavy RAM usage during closed applications).
I see two solutions:
-Write images directly to the application path, which would result in longer loading phases in EVERY render process
-Simply break the capturing and delete all the process, which obviously also sucks, as the captures might have been essential

I still tend to the second option. What do you think?

I cannot imagine a workaround so far, except to manually check for this error with a try loop, but am gonna try to approach this issue with the next release (within the next 12h).

@polarby polarby added discussion render capturing issues that involve capturing of frames labels Apr 1, 2023
@michelesandroni
Copy link
Author

I guess the 2nd sounds good (breaking / aborting the capture).
Are you going to update the example to show how to manage this scenario as well?
The app developer could simply show a message saying "please don't close or minimize the app while exporting a video".

@polarby
Copy link
Owner

polarby commented Apr 2, 2023

I was actually not able to reproduce the error as a raised exception. For me, it only printed it in the console, and it might still do that.

Nonetheless, I release a new release (1e9859b or render: ^0.1.2) where a fatal error arises when closing the application during an active render session. You can now check for errors yourself, such as this one, and show a message to the user (Everything else would exceed the function spectrum of this plugin).

@polarby polarby closed this as completed Apr 2, 2023
@michelesandroni
Copy link
Author

Repro steps:

  1. please download the latest code zip from github for 0.1.2
  2. unzip and open the example folder in VS Code
  3. run the app on the Android Simulator
  4. please click on the "capture motion" button, then immediately go to the homescreen while the capture is still in progress

VS code halts execution and inspects the file dart:ui/painting.dart, pointing to line 1891 (using Flutter 3.7.8).

I'm also wrapping the content of the method "motionRenderCallback" in a try catch block.
I'm not closing the app but simply going to the home screen, putting the app in background.
After building the app, I've noticed that the fatal is triggered silently once in the console when minimizing, but the exception still halts execution.

Future<ByteData?> toByteData({ImageByteFormat format = ImageByteFormat.rawRgba}) {
    return _futurize((_Callback<ByteData> callback) {
      return _toByteData(format.index, (Uint8List? encoded) {
        callback(encoded!.buffer.asByteData()); // <--------------------- this line
      });
    });
  }
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.8, on macOS 13.3 22E252 darwin-arm64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.77.0)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

@polarby
Copy link
Owner

polarby commented May 12, 2023

Sorry for not seeing the update! I am currently too tight with other projects (unpredictable duration :( ). As far as i can remember this issue was difficult for me to resolve, as I didn't get the error, only the console message. I will have to do a bigger deep dive, the next time! Weird, I thought the update must have resolved to switch screens.

Don't hesitate to debug by yourself, this might be faster, especially as you have the correct error path!

@michelesandroni
Copy link
Author

Yes, I understand, no problem. The issue is also a bit inconsistent, I'm working on MacOS for iOS development so that might affect things as well. Thanks in advance!

@polarby polarby added the help wanted Extra attention is needed label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion help wanted Extra attention is needed render capturing issues that involve capturing of frames
Projects
None yet
Development

No branches or pull requests

2 participants