kaltura / kme-sdk-android

Kaltura Meeting Experience SDK for Android
GNU Affero General Public License v3.0
2 stars 2 forks source link

Crash on screen rotation on RoomActivity #149

Open flamyoad opened 3 years ago

flamyoad commented 3 years ago

Steps to reproduce: 1 . Join any room

  1. Click "Go" on the camera PreviewDialog to proceed
  2. Wait for both contentFragment and renderFragment to appear on screen.
  3. Rotate the screen now, and the app will crash

Stacktrace:

    Process: com.kme.kaltura.demo, PID: 24134
    kotlin.UninitializedPropertyAccessException: lateinit property adapter has not been initialized
        at com.kme.kaltura.kmeapplication.view.fragment.RoomRenderersFragment.access$getAdapter$p(RoomRenderersFragment.kt:25)
        at com.kme.kaltura.kmeapplication.view.fragment.RoomRenderersFragment$publisherAddObserver$1.onChanged(RoomRenderersFragment.kt:169)
        at com.kme.kaltura.kmeapplication.view.fragment.RoomRenderersFragment$publisherAddObserver$1.onChanged(RoomRenderersFragment.kt:25)
        at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
        at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:144)
        at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:443)
        at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:395)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
        at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
        at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
        at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
        at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
        at androidx.fragment.app.FragmentViewLifecycleOwner.handleLifecycleEvent(FragmentViewLifecycleOwner.java:51)
        at androidx.fragment.app.Fragment.performStart(Fragment.java:2737)
        at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:355)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1192)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1495)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2617)
        at androidx.fragment.app.FragmentManager.dispatchStart(FragmentManager.java:2575)
        at androidx.fragment.app.FragmentController.dispatchStart(FragmentController.java:258)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:550)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1436)
        at android.app.Activity.performStart(Activity.java:8174)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3565)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8057)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
kaltura-hooks commented 3 years ago

Hi @flamyoad,

Thank for you reporting an issue and helping improve Kaltura!

To get the fastest response time, and help the maintainers review and test your reported issues or suggestions, please ensure that your issue includes the following (please comment with more info if you have not included all this info in your original issue):

For general troubleshooting see: https://github.com/kaltura/platform-install-packages/blob/Jupiter-10.13.0/doc/kaltura-packages-faq.md#troubleshooting-help

If you only have a general question rather than a bug report, please close this issue and post at: http://forum.kaltura.org

Thank you in advance,

flamyoad commented 3 years ago

The reason lies in the initialization code in your RoomRendererFragment.kt

https://github.com/kaltura/kme-sdk-android/blob/43eda537c4db0cb4eda5eda42b803eac46f14c68/kmeapp/src/main/java/com/kme/kaltura/kmeapplication/view/fragment/RoomRenderersFragment.kt#L42-L47

https://github.com/kaltura/kme-sdk-android/blob/43eda537c4db0cb4eda5eda42b803eac46f14c68/kmeapp/src/main/java/com/kme/kaltura/kmeapplication/view/fragment/RoomRenderersFragment.kt#L99-L111

In your code, adapter is initialized when onGlobalLayout() is invoked, and the app will crash because the setupViewModel() is called() before your initialize your adapter variable.

    private fun setupUI() {
        rvRenderers.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
            override fun onGlobalLayout() {
                . . . .
                setupViewModel() // Moved to here
            }
        })
    }