Android-GoldenEye icon indicating copy to clipboard operation
Android-GoldenEye copied to clipboard

Frequent crash when I try to set flashMode right after the build() of GoldenEye object

Open Danyaga opened this issue 5 years ago • 2 comments

Basically my questions are: What is the best way (and timing) to turn off the flash feature? Is there a way to turn off the flash feature in the GoldenEye.Builder?

I build the GoldenEye object with these line of code:

////// from CameraActivity.onCreate()
this.goldenEye = GoldenEye.Builder(this)
                .setCameraApi(CameraApi.CAMERA1)
                .build()

this.goldenEye?.config?.flashMode = FlashMode.OFF
//////
java.lang.RuntimeException: Unable to start activity ComponentInfo{OMISSIS}: kotlin.UninitializedPropertyAccessException: lateinit property _config has not been initialized
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: kotlin.UninitializedPropertyAccessException: lateinit property _config has not been initialized
        at co.infinum.goldeneye.GoldenEye1Impl.getConfig(GoldenEye1Impl.kt:54)
        at OMISSIS:124)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

Danyaga avatar Jun 07 '19 10:06 Danyaga

Hello @Danyaga ,

I am unable to reproduce the issue. By default the config should not be available until it is initialized. Could you explain how did you reproduce this issue? Do you have some navigation in between?

domagojkorman avatar Jun 14 '19 13:06 domagojkorman

Not at all. Just the above lines at the end of Activity.onCreate().

IMHO you should avoid to use a lateinit var for that property, because it seems that is not ready to be used right after the call of build().

Do you think is better if I "turn off" the flash in block of code onReady that i put as input of .open()?

EDIT1 Probably it is not ideal to have this kind of timeline of calls:

  • Activity.onCreate(): - GoldenEye.Builder().[...].build() - goldenEye?.config?.flashMode = FlashMode.OFF
  • Activity.onStart(): goldenEye.open()
  • Activity.onStop(): goldenEye.release()

as you describe in the example Activity, in particular about the timing that, as you know for sure, they may not be so precise on some Android devices in some particular corner cases.

EDIT2 Ok, right now i found this comment from you guys, in the code about the config object

Currently opened camera configuration. Be sure to access it only after * [InitCallback.onReady] is received.

So this how my code looks like now: https://gist.github.com/Danyaga/2ea0d8b8c416e8fe6ad18b28c634990e

Danyaga avatar Jun 18 '19 08:06 Danyaga