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

Repeatedly calling fotoapparat.takePicture() causes app to crash #418

Open
LaVlad opened this issue Nov 9, 2021 · 0 comments
Open

Repeatedly calling fotoapparat.takePicture() causes app to crash #418

LaVlad opened this issue Nov 9, 2021 · 0 comments

Comments

@LaVlad
Copy link

LaVlad commented Nov 9, 2021

I'm making a simple Android app that needs to repeatedly make photos every second while it's operational. I delete the photos that are more than a minute old from the file system. This I achieve through roughly the following code:

timer = timerTask {
                val curFile = File(photoFolder, System.currentTimeMillis().toString() + ".png")
                fotoapparat?.takePicture()?.saveToFile(curFile)
                photoFiles.add(curFile)
                if (photoFiles.size > 60) {
                    photoFiles[0].delete()
                    photoFiles.removeFirst()
                }
            }
            Timer("SettingUp", false).scheduleAtFixedRate(timer, 2, 1000)

Everything works fine for a while, however the app consistently ceases to function after roughly 14 minutes of taking pictures. IDE doesn't throw any error upon termination, it just stops. Moreover, after that if the app is launched again it will crash shortly after the launch. This is not fixed by deinstalling and reinstalling the app or restarting the emulator. The only fix I was able to discover is wiping user data from the emulator.

After some testing and experimentation I was able to narrow the issue down to the line where pictures are taken (if this line is commented the app works indefinitely just fine):

fotoapparat?.takePicture()?.saveToFile(curFile)

Moreover, upon more experimentation I discovered, that even after disabling saving the photos (the saveToFile() part), calling fotoapparat.takePicture() alone still leads to the same effect within the same timespan.

I've monitored the app through Android Studio memory profiler and discovered the steady increase in "Others" memory consumption throughout the process, seemingly displacing other memory categories, until the big spike leads to app's crash.

image

How did you initialize FA?

var fotoapparat: Fotoapparat? = null
var fotoapparatState : FotoapparatState? = null

public override fun onCreate(state: Bundle?) {
        super.onCreate(state)

        createFotoapparat()
        fotoapparatState = FotoapparatState.OFF
}

private fun createFotoapparat(){
    val cameraView = findViewById<CameraView>(R.id.camera_view)

    fotoapparat = Fotoapparat(
        context = this,
        view = cameraView,
        scaleType = ScaleType.CenterCrop,
        lensPosition = back(),
        logger = loggers(
            logcat()
        ),
        cameraErrorCallback = { error ->
            println("Recorder errors: $error")
        }
    )
}

override fun onStart() {
    super.onStart()
    fotoapparat?.start()
    fotoapparatState = FotoapparatState.ON
}

What was the result you received?

The app crashes without errors after approximately 14 minutes of consecutively taking pictures.

What did you expect?

App proceeds to operate indefinitely.

Context:

  • FA version: 2.7.0
  • Devices/APIs affected: Pixel 5 API 29 (Android studio emulator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant