Open michelesandroni opened 1 year ago
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).
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".
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 (1e9859b7fcc2b309ae0bfd9280aac6d3619bb52f 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).
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
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!
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!
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.. (dart:ui/painting.dart:1891:25)
`
Expected behavior: The rendering / capture process should be paused?
The exception refers to line 1891 of painting.dart
Any ideas or workarounds on how to avoid this would be great! Thanks a lot.