Open jpribble opened 6 years ago
I have the speculation this is because the camera doesn't have time to stop properly (because it runs in a separate thread).
@jpribble if that's not your production code logs, would you mind adding a thread sleep e.g. 200ms and see if that solves it?
I'm not able to consistently reproduce this so I don't think I'll be able to test that. However, I suspect this is being caused by a quick configuration change right after the activity is launched. I was able to reproduce similar issues with the following steps:
When the device is unlocked and returns the camera, it crashes. I confirmed that the Activity is receiving a configuration change when the device is unlocked (probably caused by the keyboard). I was able to "fix" this by adding configChanges="..." to the camera Activity so it doesn't get recreated due to config changes. I believe the configChanges flag will also help me work around the issue originally described above. However, it'd still be good to still investigate the root issue to help others avoid it in the future.
Could this be a remnant of #115 still lingering? On the physical devices I tested (galaxy s6,s5) #115 was extremely reproducible pre 2.0, but since the 2.0 release I haven't had it occur yet on those devices. I am able to observe the issue occur in the Android Studio Emulator but that could be camera emulation related.
If it is helpful though, If you launch the default Fotoapparat sample in the emulator running a Nexus 5 API 22, hit the home button and return to the app, the preview will be blank.
Can confirm, have this issue (#115) even after updating to 2.2.0 from 1.5.0, for now using post delayed as a hacky workaround. I managed to reproduce it on Nexus 5, Samsung S7 using Fotoapparat's sample app.
Here i start the app, go to overview(recents) and back: https://gfycat.com/BeautifulFlusteredAsiantrumpetfish
When going to overview and back camera can either manage to start or not: https://gfycat.com/CourteousBabyishDunlin
Why this issue occurs?? Library is really bad if this continue on... Should I switch all my app code to CameraKit? This issue should be a priority number 1.
Is there any workaround for this issue?
Just managed to get a device that i used to reproduce this bug year ago. It is Samsung S7 edge (SM-G935FD)(Android 6.0)
The bug is consistently reproduced both in 2.2.0 (as before) and in 2.7.0 (version with this fix). If we add delay before camera start:
override fun onStart() {
super.onStart()
if (permissionsGranted) {
cameraView.postDelayed({
fotoapparat.start()
adjustViewsVisibility()
}, 20)
}
}
then bug is no longer reproduced and camera always manages to start. So in 2.7.0 we are still using that workaround.
@Diolor can you reopen this bug?
EDIT: I should add that i used sample app for tests and workaround example. EDIT2: Removed delay in on stop.
@Raenar4k this is really bad news... I have released 2.7.0 version, by removing handlers... How did you reproduced bug? Did bug appears always or at some times?
It is easily reproduced on that device, when going to home screen and back to app from recents. There is a gif that illustrates this: https://github.com/RedApparat/Fotoapparat/issues/191#issuecomment-363411738
@Raenar4k i have tested also on many devices.. I found that you must call fotoappart.stop() on onPause, not onStop. Can you try that on your phone?
@Raenark4k.. Oh ok. Let me know if library works well it you use handler only for starting session? I can't use it onStop because it creates issues when switching fragments from front and back. I would like to avoid some hacky solutions for switching cameras. By my logic Handler on onStart should be enough
What are you trying to achieve or the steps to reproduce?
Very rarely (about 1 in 50 times), the camera fails to start. The camera preview displays a black screen and the frame processor doesn't receive any frames. When this happens, I have to force kill and relaunch the app to get the camera working again. The logs show that my Activity is very quickly created, destroyed, and recreated when this issue appears. The second time the Activity is created, it is missing the "Fotoapparat: Device: selectCamera" and "Fotoapparat: CameraDevice: open" logs. Here are the full logs:
How did you initialize FA?
Context: