0

I am making an app that you can video call through WebRTC. On the first call to the Activity for WebRTC, everything runs smoothly, but on the second time, I get crashes due to Null Pointer exception on my localPeer object:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void org.webrtc.PeerConnection.setRemoteDescription(org.webrtc.SdpObserver, org.webrtc.SessionDescription)' on a null object reference

Before finishing the activity, I have tried clearing up the resources onDestroy as such :

  if (localPeer != null) {
            localPeer.close();
            localPeer.dispose();
        }

Am I doing anything wrong to clear up the resources that may cause the crash? Or what causes peerConnectionFactory.createPeerConnection() to return null?

Lee Boon Kong
  • 1,007
  • 1
  • 8
  • 17
  • Check out my this answer: https://stackoverflow.com/questions/51074131/webrtc-native-crashed-when-i-call-peerconnection-close/51077216#51077216 It might be the issue. – NeverHopeless Jan 17 '19 at 10:58

1 Answers1

0

Alright I found the problem for this.

I have a Client class that acts as a wrapper for my Socket.IO connections. Let's call it ClientClass. Within the ClientClass I have a private static ClientClass instance that can only be accessed through calling the class's static getInstance() method.

During the closing of the connection I forgot to set it to null as such:

  public void close() {
    socket.emit("bye");
    socket.off();
    socket.disconnect();
    socket.close();
    roomName = null;
    socket = null;
    instance = null; //I forgot this line
}

It's a pretty weird issue that is tricky to debug from the errors, unable to be traced by just reading the error logs.

Lee Boon Kong
  • 1,007
  • 1
  • 8
  • 17