-
Notifications
You must be signed in to change notification settings - Fork 163
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
Plugin crashes Android app when switching between apps #3
Comments
Thanks for the issue! I've got a couple of questions, because I'm not able to reproduce the bug.
|
Hi Here' s my Flutter doctor output: Doctor summary (to see all details, run flutter doctor -v): • No issues found! I'm using a standard emulator (I think) Nexus 5X API P The phone I test on is a Motorola G5S Plus running Android 7.1.1 Here's the output for the error when I run the test app on my device Launching lib/main.dart on Moto G 5S Plus in debug mode... Build fingerprint: 'motorola/sanders_n/sanders_n:7.1.1/NPSS26.116-61-11/18:user/release-keys' |
I'm having a hard time at figuring this out, so I hope you have patience 😅 . It would be nice if you could try on another physical device. I think that if it doesn't work on that phone then it may be because of some configuration on the gradle of the project. (It would be really really weird that it doesn't work on any of your devices) Another thing I would try is making a new flutter project and import this library as a dependency following the instructions in the readme and test it with this: import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fast_qr_reader_view/fast_qr_reader_view.dart';
List<CameraDescription> cameras;
Future<Null> main() async {
cameras = await availableCameras();
runApp(new CameraApp());
}
class CameraApp extends StatefulWidget {
@override
_CameraAppState createState() => new _CameraAppState();
}
class _CameraAppState extends State<CameraApp> {
QRReaderController controller;
@override
void initState() {
super.initState();
controller = new QRReaderController(cameras[0], ResolutionPreset.medium, [CodeFormat.qr], (dynamic value){
print(value); // the result!
// ... do something
// wait 3 seconds then start scanning again.
new Future.delayed(const Duration(seconds: 3), controller.startScanning);
});
controller.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
controller.startScanning();
});
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return new Container();
}
return new AspectRatio(
aspectRatio:
controller.value.aspectRatio,
child: new QRReaderPreview(controller));
}
} Last resort: Could you try this project: https://github.com/firebase/quickstart-android/tree/master/mlkit ? If that one doesn't work, then we know is a MLkit error and we can ask them for help, if it does, then it's something wrong with this project or Flutter. Last last resort: use a different computer to run the project |
Thanks. |
Hello! Any news on this? I have the same problem, plugin works fine on iOS but crashes on Android device or keeps throwing exceptions on emulator: I/flutter ( 4088): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3424 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true. |
@dragosholban Did you try what I said in my last comment? Also, can you provide:
|
@facundomedica I made a new Flutter project, installed the plugin as described in the docs, user the code you posted above and it still crashes :(
|
I'm testing on a Huawei P20 Pro. I also tested the camera plugin you based your code on, but that works fine, with no issues. So I guess it's something in this project that goes wrong when the activity pauses and the camera stops... |
Ok, I think I might have a clue, the problem seems to be here: https://github.com/facundomedica/fast_qr_reader_view/blob/master/android/src/main/java/co/apperto/fastqrreaderview/FastQrReaderViewPlugin.java#L95-L146 I'll compare it side to side with how it's done in MLKit, because I might have missed a method. I will take a look in a couple of hours but feel free to take a look for yourself and report any findings. Take special care with |
@facundomedica did you find anything yet? |
@dragosholban I haven't been able to replicate the issue on the devices I have available (BLU Vivo 8 and a Samsung Galaxy S4 mini) so I can switch between apps and it never crashes 🤦♂️ . I will try with different emulators until I get the error. |
This is very strange, I tested on a Nexus 5X and it crashed too. I will test on a Samsung Galaxy S4 mini. I also started to investigate, it seems the crash happens on dispose, I guess the firebase reader is still connected and tries to read the images when the camera shuts down. I haven't found the exact place, but it's somewhere around this. |
Unfortunately I am not able to run on Samsung Galaxy S4 mini, I get the following error:
|
Oh yes, I forgot that I had updated the OS with a non-factory one, sorry about that |
Hi again! I created a new project just for testing this issue: https://github.com/dragosholban/flutter_qr_test Maybe you can test it too, after you scan a QR Code, press back and the app will crash. I tried to find the problem, but I had no success. Please let me know if you can at least replicate the issue using this project. Thanks! |
Any luck recreating the problem? I'm sure you've got a day job and this stuff is pretty tricky. It does look like unloading / shutting down the camera is where the problem lies. |
I got it to throw an exception with the project @dragosholban provided on a simulator, but it did not crash, it just threw this exception I'll try to give this an entire day of debugging this week, if you find anything more please post it here, I'm having a hard time debugging this. |
@facundomedica please use a real device to test, not the simulator. It does not crash on the simulator. Use a real device, scan some codes and press back. |
@dragosholban this might sound a bit weird, but can you give me the QR codes you are testing with? I tested on a physical device and sadly it works... Anyway, as a final resort, I will set up another repo or branch with some "blind tests" with stuff changed that I suppose can fix the issue and you can tell me if they fix it for you or not. If you help me with this I'll list your names in a "collaborators" or "acknowledgments" file or something like that. |
@facundomedica this is crazy :( I scanned random codes generated here: https://www.the-qrcode-generator.com/ The this is that the app crashes even without scanning any codes. The crash happens when you "go back" to the previous screen, or when you try to switch to another app. It seems the camera stops but, somehow the MLKit is still processing images and crashes. I noticed that if I change the code to manually stop the scan, then, after a few seconds, I "go back" it does not crash anymore. It only happens when scanning is active. |
Hi @facundomedica & @dragosholban. I'm getting the same behaviour as @dragosholban. I'm testing on a Samsung S9 Android 8.0 & Motorola G5S Plus Android 7.1.1. The apps I'm building currently use Flutter Channel beta, v0.5.1. I made a Play Store internal release & all 5 users encountered the same problem. I'll try & do some more testing tomorrow. |
Hello all! Can you try this in your pubspec.yaml? # fast_qr_reader_view: ^0.1.2
fast_qr_reader_view:
git:
url: git://github.com/facundomedica/fast_qr_reader_view.git
ref: blindtest Also @ghunter99 you told me that you were distributing an app internally, do you have crashlytics set up? I can't believe that my first cool open source project has a bug this difficult to catch 🤦♂️ |
No I don't but I will set up crashlytics & get back to you |
Hi @facundomedica Crashlytics - plaintext stacktrace downloaded by Gary Hunter at Mon, 03 Sep 2018 20:16:29 GMTURL: https://fabric.io/xyris-software-australia-pty-ltd/android/apps/au.com.xyris.eddflutter/issues/5b8d96356007d59fcda29b9f?time=last-seven-days/sessions/5B8D95DA005600017B684EFAF46CBD33_DNE_0_v2Organization: Xyris Software (Australia) Pty LtdPlatform: androidApplication: edd_flutterVersion: 5.0.999 (14)Bundle Identifier: au.com.xyris.eddflutterIssue #: 3Issue ID: 5b8d96356007d59fcda29b9fSession ID: 5B8D95DA005600017B684EFAF46CBD33_DNE_0_v2Date: 2018-09-03T20:14:00ZOS Version: 7.1.1Device: Moto G (5S) PlusRAM Free: 30.4%Disk Free: 41.6%#0. Crashed: main -- Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=513469796, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {au.com.xyris.eddflutter/au.com.xyris.eddflutter.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void java.lang.Runnable.run()' on a null object reference Caused by java.lang.NullPointerException: Attempt to invoke interface method 'void java.lang.Runnable.run()' on a null object reference #0. Crashed: main #1. OkHttp ConnectionPool #2. Measurement Worker #3. Queue #4. pool-9-thread-1 #5. Answers Events Handler1 #6. Queue #7. FirebaseMLHandler #8. Queue #9. Queue #10. Queue #11. Queue #12. pool-4-thread-1 #13. pool-3-thread-1 #14. GoogleApiHandler #15. Crashlytics Exception Handler1 #16. HeapTaskDaemon #17. FinalizerDaemon #18. GoogleApiHandler #19. ReferenceQueueDaemon #20. ImageDecoderThread #21. Queue #22. Queue #23. FinalizerWatchdogDaemon #24. pool-7-thread-1 #25. Queue |
I have been able to recreate the issue in a coworker's device. Also, here is a related issue: https://stackoverflow.com/questions/51425658/sigsegv-crash-with-firebase-mlkit-barcode-scanner |
Okay, big update here! The problem seems to be with devices that input more images than it can process, so when you go to background it keeps processing lots of data. I'm trying to solve this with a throttle flag so it process "just enough" but it seems to slow down everything (https://github.com/firebase/quickstart-android/blob/master/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/VisionProcessorBase.java). If this doesn't solve it, I might have to rewrite the Android class completely. |
Great work! |
Hi @facundomedica |
@ghunter99 the Eventway app is @dragosholban's, not mine. Also, it didn't crash, only froze right? @sestegra thanks for joining the conversation! I would guess that the throttle should throttle the image decoding and not the imagereader, so the surface will still get updates and the decoder only when it's not throttling. I'll try to upload something this week but feel free to experiment and make a pull request! |
Sorry, a commit closed this automatically! |
I've just pushed an update in which almost everything was rewritten in Android. The code is a bit messy but it should be easy to clean it up once we know it is working. From my tests I've seen a serious improvement in performance and speed to read codes. Try it out with this: fast_qr_reader_view:
git:
url: git://github.com/facundomedica/fast_qr_reader_view.git |
@facundomedica Wow!! A huge improvement. Much faster & much more stable. It still sometimes crashes though. I've attached a Crashlytics crash report. au.com.xyris.eddflutter_issue_17_crash_5BA09E9403BE00012EE2DAB4D0E2A368_DNE_0_v2.txt |
@facundomedica It works well on my phone now. |
@ghunter99 there was a duplicated start, re-download the package and try again |
Hi @facundomedica. I still seem to get crashes. Attached is a crash report which I hope is helpful. au.com.xyris.eddflutter_issue_17_crash_5BA15BB90257000161FDA6D86CFFC3CC_DNE_0_v2.txt |
@ghunter99 It fails in a line where preview isn't checked for null, I just pushed a change, let me know if that fixes it for you! |
Thanks @facundomedica. |
@facundomedica, I did a lot of testing today & found 2 things. Hope this is helpful and easy to reproduce. First thing is, if you just add the fast_qr_reader_view package to an app I attached the code main.dart file that I was using to create this behaviour. D/AndroidRuntime(18205): Shutting down VM |
@facundomedica 2nd thing I found: I can reliably cause app I've been working on to crash. Hope this is helpful. Background
Steps to cause crash:
I attached a minimal main.dart that is based on your example code & default Flutter app. I've also attached a crashlytics report from a crash. au.com.xyris.eddflutter_issue_17_crash_5BA1C89802B0000103243D1EB519C677_DNE_0_v2.txt |
...lastly, just wanted to say it is a pretty cool package you've made. I'm hoping to use it in a Flutter port of an iOS app that has 1.2M downloads here in Australia. ....am so impressed with Flutter! |
Yeah i can confirm, even if the screen goes in standby, when resuming the app just crashes.
|
Has this bug been solved ? @facundomedica |
Hi! I didn't get the time to check on this. I tried with the instructions @ghunter99 provided but I haven't been able to reproduce the issue! 🤦♂️ |
I made some changes, please try again! |
No, the problem still happens. You simply have to open the camera, go to another widget, and then try to switch app. It seems like the dispose method is never called or the camera is never closed. I'm calling it like a new object page from a StreamBuilder. This is still what i get: |
I've copied one of the answers from here (flutter/flutter#18348) and pushed the change. Can you try now? |
@facundomedica @Nik99 does not crash now for me 👍 |
Works for me too! |
Great! I've already pushed 0.1.4 to the package index (or whatever people call https://pub.dartlang.org) |
The app doesn't work again.
|
My app needed to be published today but this is blocking it. Can you fix it ? @facundomedica |
@Nik99 that doesn't seem related to this issue nor to this library, but to a project config thing. Check this: https://stackoverflow.com/a/46339401/5240559 |
I'm sorry. You are right. Flutter was spitting me out errors on your library but it is not. |
Thanks for adding the ability to scan different barcodes.
Works brilliantly!
I've run into a bug that I hope us easy reproduce.
(that's the button on the bottom on the right side) the example program crashes with the
following error:
F/libc (28681): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x26780000 in tid 29800 (FirebaseMLHandl)
I get a similar error when using the Android emulator:
F/libc (14291): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xabb36d70 in tid 14373 (FirebaseMLHandl), pid 14291 (yris.eddflutter)
Let me know if I can be of any assistance!
The text was updated successfully, but these errors were encountered: