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

Capture fails after a restart of the camera #117

Closed
2 of 6 tasks
arvinkx opened this issue Jan 17, 2019 · 7 comments
Closed
2 of 6 tasks

Capture fails after a restart of the camera #117

arvinkx opened this issue Jan 17, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@arvinkx
Copy link

arvinkx commented Jan 17, 2019

Describe the bug
Capture doesn't work after stopping and restarting the camera in release 2.7.0. An error is not generated and the picture taken listener is not invoked. This showed up in this latest release (2.7.0), it doesn't seem to occur on 2.6.1.

To Reproduce
Steps to reproduce the behavior:

  1. Start camera using start
  2. Stop camera using stop(false)
  3. Start camera again using start
  4. Call capture and the dimming UI animation occurs but addPictureTakenListener or addCameraErrorListener are never called

Expected behavior
Calling capture should call either the error listener or the picture taken listener.

Using ProGuard

  • with ProGuard
  • without ProGuard

Device (please complete the following information):

  • Device: S8+
  • OS: 8.0.0
  • API: 27
  • App version 0.1

Branch Name (if using as a local module)

  • master
  • development
  • release
  • other (please specify)
@pcm2a
Copy link
Contributor

pcm2a commented Jan 17, 2019

Is this reproducible in the sampleApp provided with the library?

@arvinkx
Copy link
Author

arvinkx commented Jan 17, 2019

Not sure, can't get the sample app to compile. It complains that File google-services.json is missing. The Google Services Plugin cannot function without it. Do I need to create a Firebase project in the console and download a google-services.json file to be able to run the sample app?

@pcm2a
Copy link
Contributor

pcm2a commented Jan 17, 2019

I had to include a google-services.json in order to compile it. I'm not sure why there is a need to have that in the project. @pvasa is that a dependency that could be removed? I also had to add gradle wrappers into a few sub projects.

@arvinkx
Copy link
Author

arvinkx commented Jan 17, 2019

I can confirm this issue exists in the sample app as well by leaving the app and coming back. Flash will fire but the picture is not taken and no preview is shown.

@pvasa
Copy link
Owner

pvasa commented Jan 18, 2019

I had to include a google-services.json in order to compile it. I'm not sure why there is a need to have that in the project. @pvasa is that a dependency that could be removed? I also had to add gradle wrappers into a few sub projects.

@pcm2a @arvinkx The sampleApp demos barcode detection implementation using firebase api as a demo for preview frame listener that is why it requires google-services.json. Please refer this google help article for instructions on generating google-services.json

@pvasa pvasa added the bug Something isn't working label Jan 18, 2019
@arvinkx
Copy link
Author

arvinkx commented Jan 18, 2019

@pvasa Not really familiar with Kotlin but I believe the issue is related to this block of code in CameraView.kt:

override fun onPictureTaken(imageData: ByteArray) {
    coroutineScope.launch {
        pictureTakenListeners.forEach {
               it(imageData)
           }
      }
}

Once stop is called without removing the listeners, starting the camera again and calling capture in debug mode in the sample app, gets to the line with pictureTakenListeners but doesn't call the block inside launch when breakpoints are set. Hope this helps as I'm not really familiar enough with Kotlin to know why that block is not being called. I also do see this in the debugger: kotlinx.coroutines.JobCancellationException: Job was cancelled; job=JobImpl{Cancelled}@d922855

@pvasa
Copy link
Owner

pvasa commented Jan 20, 2019

I also do see this in the debugger: kotlinx.coroutines.JobCancellationException: Job was cancelled; job=JobImpl{Cancelled}@d922855

@arvinkx good catch that was the exact issue. When a scope is created using CoroutineScope(coroutineContext) function, it attaches the scope to a new Job context. So when coroutineScope.cooutineContext.cancel() is called it cancels the job and thus no more coroutines can be created using that scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants