Search code examples
iosswiftuiviewexc-bad-accessquickblox

Thread 1: EXC_BAD_ACCESS (code=1, address=0x20) When subView


I got a strange error. Thread 1: EXC_BAD_ACCESS (code=1, address=0x20) When a View subView on another view.

Both view object not nil.

How do I solve this issue.

Edit: I am implementing a video chat code with VOIP.

When an incoming call comes and after accept the call. I need to display a screen. This screen is showing fine and other UIElements button etc.. (including button functionalities) everything is working as expected for audio calls.

But, in video call after receive the remote user video I am trying to subView to a view . I could view the remote user screen for a second. suddenly get crashed (Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)).

func session(_ session: QBRTCBaseSession, receivedRemoteVideoTrack videoTrack: QBRTCVideoTrack, fromUser userID: NSNumber) {

  if (session as! QBRTCSession).id == self.session?.id {

      let remoteView :QBRTCRemoteVideoView = QBRTCRemoteVideoView()
      remoteView.videoGravity = AVLayerVideoGravity.resizeAspect.rawValue
      remoteView.clipsToBounds = true
      remoteView.setVideoTrack(videoTrack)
      remoteView.tag = userID.intValue

      var frame = self.mainVideoView.bounds
      frame.origin.y = 0
      remoteView.frame = frame

      self.view.addSubview(remoteView)
     }
}

Where receivedRemoteVideoTrack function is a delegate method for the remote video.

enter image description here

enter image description here


Solution

  • Keep in mind that Metal only available with A7 processors or higher. I can suggest you force OpenGLES drawings instead of Metal, for now, just do this:

    QBRTCRemoteVideoView.preferMetal = NO