Closed torepaulsson closed 3 years ago
Hello
I am seeing the same issue with RemoveDataChannel:
Environment: MR-WebRTC: Latest stable 2.0.2 Platform: Windows 10.0.19042 Build 199042 Architecture: x64 Target device: Windows Desktop
Thanks
Fixed with @torepaulsson's PR #799, thanks for the contribution! Closing this.
Describe the bug When calling PeerConnection.RemoveDataChannel an InvalidOperationException is thrown.
To Reproduce Steps to reproduce the behavior:
Expected behavior Data channel connection removed and resources cleared from memory
Environment
Additional context I noticed this issue when I was using data channels and wanted to remove them from the peer connection. It always crashed, thought I would try to reproduce it in a easier context.
From what I can tell while debugging, it seems that the RemoveDataChannel method removes the channel from the list, calls the c++ implementation of peer_connection.RemoveDataChannel, it performs some work and fires an DataChannelRemoved callback. A lot of work is done in these callback handlers, it seems some work is duplicated, especially the dataChannel.DestroyNative() method call.
As the code looks now it seems like you probably would get multiple RemoveDataChannel events if you initialize the removal, but when the callback from the mr-webrtc library is called we also destroy the data channel. I believe we should not call destroy native in the PeerConnection.RemoveDataChannel, probably only do that in the PeerConnectionInterop.DataChannelRemovedCallback call?
I've created a branch where I've investigated the issue, and tried to fix it, https://github.com/microsoft/MixedReality-WebRTC/compare/master...torepaulsson:users/torep/fix-remove-data-channel