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

NullPointerException in the MainRender.getSurfaceTexture method #1685

Open
bhavinatharva opened this issue Dec 20, 2024 · 5 comments
Open

NullPointerException in the MainRender.getSurfaceTexture method #1685

bhavinatharva opened this issue Dec 20, 2024 · 5 comments

Comments

@bhavinatharva
Copy link

bhavinatharva commented Dec 20, 2024

Describe the bug
The app crashes when starting a stream due to a NullPointerException in the MainRender.getSurfaceTexture method.

To Reproduce
Steps to reproduce the behavior:

Open the app.
Navigate to the stream setup screen.
Start a new screen broadcast stream session.
Observe the app crash.

Expected behavior
The stream should start successfully without crashing.

Screenshots
Screenshot 2024-12-20 at 2 21 55 PM

Smartphone (please complete the following information):

Library version: 2.5.4
Device: Motorola Malta
OS: Android 10 (SDK 29)
Media server: [e.g. SRS, version 5.0]
Class used: [e.g. RtmpCamera1]
Additional context
Crash logs from Play Console:

Exception java.lang.RuntimeException:  
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4873)  
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:4914)  
  at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:51)  
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)  
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)  
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2041)  
  at android.os.Handler.dispatchMessage (Handler.java:107)  
  at android.os.Looper.loop (Looper.java:214)  
  at android.app.ActivityThread.main (ActivityThread.java:7386)  
  at java.lang.reflect.Method.invoke  
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)  
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:980)  
Caused by java.lang.NullPointerException:  
  at com.pedro.encoder.input.gl.render.MainRender.getSurfaceTexture (MainRender.kt:176)  
  at com.pedro.library.view.GlStreamInterface.getSurfaceTexture (GlStreamInterface.kt:118)  
  at com.pedro.library.base.StreamBase.startSources (StreamBase.kt:451)  
  at com.pedro.library.base.StreamBase.startStream (StreamBase.kt:156)  
  at com.atharvasystem.quickscreenrecorder.services.ShareScreenService.startStream (ShareScreenService.kt:168)  
  at com.atharvasystem.quickscreenrecorder.ui.streams.StreamSourceActivity.activityResultContract$lambda$0 (StreamSourceActivity.kt:102)  
  at com.atharvasystem.quickscreenrecorder.ui.streams.StreamSourceActivity.$r8$lambda$LtWeMkLkNKtetOKKVdlgnnLpK3s (Unknown Source)  
  at com.atharvasystem.quickscreenrecorder.ui.streams.StreamSourceActivity$$ExternalSyntheticLambda2.onActivityResult (D8$$SyntheticClass)  
  at androidx.activity.result.ActivityResultRegistry.doDispatch (ActivityResultRegistry.kt:371)  
  at androidx.activity.result.ActivityResultRegistry.dispatchResult (ActivityResultRegistry.kt:331)  
  at androidx.activity.ComponentActivity.onActivityResult (ComponentActivity.kt:786)  
  at androidx.fragment.app.FragmentActivity.onActivityResult (FragmentActivity.java:151)  
  at android.app.Activity.dispatchActivityResult (Activity.java:8110)  
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4866)  

@bhavinatharva bhavinatharva changed the title The app crashes when starting a screen broadcast stream due to a NullPointerException in the MainRender.getSurfaceTexture method. NullPointerException in the MainRender.getSurfaceTexture method Dec 20, 2024
@penmatsa
Copy link

penmatsa commented Dec 20, 2024

Hello,

we are also getting same above crash when using genericCamera2 with OpenGlView.

@pedroSG94
Copy link
Owner

pedroSG94 commented Dec 20, 2024

Can you give me more info about it?
Can you reproduce it using an older version? in which version is working fine?
Are you checking that prepareVideo and prepareAudio return true before startStream?

Can you share me a code example to reproduce it?

Also, the library version 2.5.5 is not the version which crash in the image because the crash line is not correct. Line 451 is this:
https://github.com/pedroSG94/RootEncoder/blob/2.5.5/library/src/main/java/com/pedro/library/base/StreamBase.kt#L451

Which no correspond to the logcat. I need know the exact compilation used

@bhavinatharva
Copy link
Author

Thank you for your response!

Validating URL and Key:
We are checking and validating the URL and stream key before starting the stream and also validating during the stream when using screen broadcast.

Reproducing Issue in Older Versions:
Apologies for the confusion earlier. The crash occurred in version 2.5.4, not 2.5.5.

Checking prepareVideo and prepareAudio:
Yes, we are ensuring that prepareVideo() and prepareAudio() return true before starting the stream.

Code Example:
Here’s a snippet of the code we are using to reproduce the issue:
Screenshot 2024-12-20 at 5 27 38 PM

Let me know if further details are required!

Crash Line and Library Version:
I’ve double-checked, and you’re right—2.5.5 doesn’t align with the crash log. The crash occurred with 2.5.4, and I’ll ensure the exact compilation details are provided. I'll update this thread with those details soon.

Thank you for your help in resolving this!

@pedroSG94
Copy link
Owner

Hello,

Can you show me code of prepareStream method?

@bhavinatharva
Copy link
Author

Yes @pedroSG94

fun prepareStream(resultCode: Int, data: Intent): Boolean {
        keepAliveTrick()
        stopStream()
        val mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data)
        if (mediaProjection == null) {
            Log.e(TAG, "MediaProjection is null")
            return false
        }
        val screenSource = ScreenSource(applicationContext, mediaProjection)
        return try {
            //ScreenSource need use always setCameraOrientation(0) because the MediaProjection handle orientation.
            //You also need remove autoHandleOrientation if you are using it.
            //You need to call it after prepareVideo to override the default value.
            genericStream.getGlInterface().setCameraOrientation(0)
            genericStream.changeVideoSource(screenSource)
            genericStream.getStreamClient().setReTries(5)
            prepareVideoAudio()
        } catch (ignored: IllegalArgumentException) {
            false
        }
    }
    
    ```

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

3 participants