aisouard / libwebrtc

:package: Google's WebRTC implementation in a single static library.
https://axel.isouard.fr/libwebrtc
Apache License 2.0
640 stars 190 forks source link

EXC_BAD_ACCESS in Signaling thread #83

Open thejsj opened 4 years ago

thejsj commented 4 years ago

I've been trying to get the AppRTCMobile example to run on MacOS (there's a version meant to run on macOS) and, after getting it to compile, started running into this issue:

Signaling Thread 0x0x4 (18): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

Stack trace:

Signaling Thread 0x0x4 (18)#0   0x0000000100006555 in rtc::scoped_refptr<webrtc::VideoFrameBuffer>::~scoped_refptr() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/base/scoped_ref_ptr.h:99
#1  0x0000000100006495 in rtc::scoped_refptr<webrtc::VideoFrameBuffer>::~scoped_refptr() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/base/scoped_ref_ptr.h:97
#2  0x0000000100027173 in rtc::VideoBroadcaster::~VideoBroadcaster() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/media/base/videobroadcaster.h:32
#3  0x0000000100026225 in rtc::VideoBroadcaster::~VideoBroadcaster() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/media/base/videobroadcaster.h:32
#4  0x00000001000524b3 in webrtc::ObjcVideoTrackSource::~ObjcVideoTrackSource() at /Users/hiphipjorge/personal/wc/TestFramework/TestFramework/WebRTC/objcvideotracksource.h:22
#5  0x0000000100052448 in rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>::~RefCountedObject() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:54
#6  0x0000000100052345 in rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>::~RefCountedObject() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:54
#7  0x000000010005236c in rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>::~RefCountedObject() at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:54
#8  0x000000010005231e in rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>::Release() const at /Users/hiphipjorge/personal/wc/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:38
#9  0x00000001007ff079 in rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>::~scoped_refptr() [inlined] at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/scoped_ref_ptr.h:99
#10 0x00000001007ff067 in rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>::~scoped_refptr() [inlined] at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/scoped_ref_ptr.h:97
#11 0x00000001007ff067 in webrtc::VideoTrack::~VideoTrack() at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/pc/videotrack.cc:28
#12 0x00000001007ffc1e in rtc::RefCountedObject<webrtc::VideoTrack>::~RefCountedObject() [inlined] at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:54
#13 0x00000001007ffc19 in rtc::RefCountedObject<webrtc::VideoTrack>::~RefCountedObject() [inlined] at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:54
#14 0x00000001007ffc19 in rtc::RefCountedObject<webrtc::VideoTrack>::~RefCountedObject() at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:54
#15 0x00000001007ffbf4 in rtc::RefCountedObject<webrtc::VideoTrack>::Release() const at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/refcountedobject.h:38
#16 0x00000001007e66b8 in rtc::scoped_refptr<webrtc::VideoTrackInterface>::operator=(webrtc::VideoTrackInterface*) [inlined] at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/scoped_ref_ptr.h:122
#17 0x00000001007e66a9 in webrtc::VideoTrackProxyWithInternal<webrtc::VideoTrackInterface>::DestroyInternal() at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/api/mediastreamtrackproxy.h:43
#18 0x00000001007dcbd5 in webrtc::internal::SynchronousMethodCall::OnMessage(rtc::Message*) [inlined] at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/api/proxy.h:141
#19 0x00000001007dcbc9 in non-virtual thunk to webrtc::internal::SynchronousMethodCall::OnMessage(rtc::Message*) ()
#20 0x000000010051e644 in rtc::MessageQueue::Dispatch(rtc::Message*) at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/messagequeue.cc:523
#21 0x00000001005423dc in rtc::Thread::ProcessMessages(int) at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/thread_darwin.mm:74
#22 0x0000000100542336 in rtc::Thread::PreRun(void*) at /Users/hiphipjorge/personal/libwebrtc2/out/webrtc/src/webrtc/base/thread_darwin.mm:58
#23 0x000000010153e9bd in _pthread_start ()
#24 0x000000010153a16b in thread_start ()

This happens when the signaling thread is instantiated and passed to CreatePeerConnectionFactory.

    _networkThread = rtc::Thread::CreateWithSocketServer();
    rtc::Thread *t = _networkThread.get();
    char name[] = "Network Thread";
    const void *var;
    t->SetName(name, var);
    BOOL result = _networkThread->Start();
    NSAssert(result, @"Failed to start network thread.");

    _workerThread = rtc::Thread::Create();
    rtc::Thread *t2 = _workerThread.get();
    char name2[] = "Worker Thread";
    const void *var2;
    t2->SetName(name2, var2);
    result = _workerThread->Start();
    NSAssert(result, @"Failed to start worker thread.");

    _signalingThread = rtc::Thread::Create();
    rtc::Thread *t3 = _signalingThread.get();
    char name3[] = "Signaling Thread";
    const void *var3;
    t3->SetName(name3, var3);
    result = _signalingThread->Start();
    NSAssert(result, @"Failed to start signaling thread.");

    NSLog(@"VideoEncoderFactory");
    const auto encoder_factory = new webrtc::VideoToolboxVideoEncoderFactory();
    const auto decoder_factory = new webrtc::VideoToolboxVideoDecoderFactory();

    // Ownership of encoder/decoder factories is passed on to the
    // peerconnectionfactory, that handles deleting them.
    _nativeFactory = webrtc::CreatePeerConnectionFactory(
        _networkThread.get(), _workerThread.get(), _signalingThread.get(),
        nullptr, encoder_factory, decoder_factory);
    NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");