-
Notifications
You must be signed in to change notification settings - Fork 3
Description
The app crashes with a NullPointerException in the plugin's native Android code when camera permissions are granted during camera initialization. This occurs at line 191 of MethodCallHandlerImplNew.kt in the instantiateCamera method.
Steps to Reproduce:
Navigate to a page that initializes the camera controller
The plugin requests camera permissions
User grants permissions
The app crashes immediately after permission grant
Expected Behavior:
The camera should initialize successfully after permissions are granted.
Actual Behavior:
The app crashes with a NullPointerException in the plugin's native code during the permission callback.
Error Log:
E/AndroidRuntime: FATAL EXCEPTION: mainE/AndroidRuntime: Process: cool.revel.beachliga, PID: 31471E/AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=9796, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {cool.revel.beachliga/cool.revel.app.MainActivity}: java.lang.NullPointerExceptionE/AndroidRuntime: at android.app.ActivityThread.deliverResults(ActivityThread.java:6332)E/AndroidRuntime: at android.app.ActivityThread.handleSendResult(ActivityThread.java:6377)E/AndroidRuntime: at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:72)E/AndroidRuntime: at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60)E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:186)E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:112)E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:84)E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2881)E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)E/AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:249)E/AndroidRuntime: at android.os.Looper.loop(Looper.java:337)E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:9593)E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)E/AndroidRuntime: Caused by: java.lang.NullPointerExceptionE/AndroidRuntime: at com.app.rtmp_stream.MethodCallHandlerImplNew.instantiateCamera(MethodCallHandlerImplNew.kt:191)E/AndroidRuntime: at com.app.rtmp_stream.MethodCallHandlerImplNew.access$instantiateCamera(MethodCallHandlerImplNew.kt:22)E/AndroidRuntime: at com.app.rtmp_stream.MethodCallHandlerImplNew$onMethodCall$1.onResult(MethodCallHandlerImplNew.kt:77)E/AndroidRuntime: at com.app.rtmp_stream.CameraPermissions$requestPermissions$1.onResult(CameraPermissions.kt:35)E/AndroidRuntime: at com.app.rtmp_stream.CameraPermissions$CameraRequestPermissionsListener.onRequestPermissionsResult(CameraPermissions.kt:86)
Environment:
Plugin Version: rtmp_streaming: ^1.0.2
Flutter Version: SDK >=3.10.0 <4.0.0
Platform: Android
Device: Tested on multiple Android devices (including MIUI devices)
Android Version: Android 14 (API 36)
Additional Context:
The crash occurs specifically when:
Navigating to the streaming page after previously stopping a stream
The app lifecycle briefly goes to inactive state during permission dialog
Permissions are granted and the plugin tries to instantiate the camera
Workaround Attempted:
Added delays before initialization (500ms-1000ms) to let plugin state stabilize
Modified app lifecycle handling to avoid stopping streams during inactive state
Added guards to prevent initialization if controller is disposed
The issue appears to be related to the plugin's internal state management during the permission flow. When onRequestPermissionsResult is called, the plugin attempts to instantiate the camera but encounters a null reference, likely because some required object or context is not properly initialized or has been disposed.
Possible Root Cause:
The instantiateCamera method at line 191 of MethodCallHandlerImplNew.kt is trying to access a null object. This could be:
A missing null check for the Flutter engine or method channel
A disposed or uninitialized camera controller reference
A race condition between permission callback and plugin lifecycle
Request:
Please add proper null checks in the instantiateCamera method and ensure all required objects are initialized before attempting to create the camera instance. Also, consider adding defensive checks in the permission callback handler to prevent crashes when the plugin state is inconsistent.