Fix assignment client crash

This commit is contained in:
David Rowe 2021-11-20 17:26:06 +13:00
parent cf57b506b5
commit 56d33b555e

View file

@ -355,13 +355,11 @@ void WDCConnection::onDataChannelStateChanged() {
<< DataChannelInterface::DataStateString(state); << DataChannelInterface::DataStateString(state);
#endif #endif
if (state == DataChannelInterface::kClosed) { if (state == DataChannelInterface::kClosed) {
// Close data channel. // Finish with the data channel.
_dataChannel->UnregisterObserver(); _dataChannel->UnregisterObserver();
// Don't set _dataChannel = nullptr because it is a scoped_refptr.
_dataChannelObserver = nullptr; _dataChannelObserver = nullptr;
_dataChannel = nullptr;
#ifdef WEBRTC_DEBUG
qCDebug(networking_webrtc) << "Disposed of data channel";
#endif
// Close peer connection. // Close peer connection.
_parent->closePeerConnection(this); _parent->closePeerConnection(this);
} }
@ -396,17 +394,21 @@ qint64 WDCConnection::getBufferedAmount() const {
#ifdef WEBRTC_DEBUG #ifdef WEBRTC_DEBUG
qCDebug(networking_webrtc) << "WDCConnection::getBufferedAmount()"; qCDebug(networking_webrtc) << "WDCConnection::getBufferedAmount()";
#endif #endif
return _dataChannel ? _dataChannel->buffered_amount() : 0; return _dataChannel && _dataChannel->state() != DataChannelInterface::kClosing
&& _dataChannel->state() != DataChannelInterface::kClosed
? _dataChannel->buffered_amount() : 0;
} }
bool WDCConnection::sendDataMessage(const DataBuffer& buffer) { bool WDCConnection::sendDataMessage(const DataBuffer& buffer) {
#ifdef WEBRTC_DEBUG #ifdef WEBRTC_DEBUG
qCDebug(networking_webrtc) << "WDCConnection::sendDataMessage()"; qCDebug(networking_webrtc) << "WDCConnection::sendDataMessage()";
if (!_dataChannel) { if (!_dataChannel || _dataChannel->state() == DataChannelInterface::kClosing
|| _dataChannel->state() == DataChannelInterface::kClosed) {
qCDebug(networking_webrtc) << "No data channel to send on"; qCDebug(networking_webrtc) << "No data channel to send on";
} }
#endif #endif
if (!_dataChannel) { if (!_dataChannel || _dataChannel->state() == DataChannelInterface::kClosing
|| _dataChannel->state() == DataChannelInterface::kClosed) {
// Data channel may have been closed while message to send was being prepared. // Data channel may have been closed while message to send was being prepared.
return false; return false;
} else if (_dataChannel->buffered_amount() + buffer.size() > MAX_WEBRTC_BUFFER_SIZE) { } else if (_dataChannel->buffered_amount() + buffer.size() > MAX_WEBRTC_BUFFER_SIZE) {
@ -422,7 +424,7 @@ void WDCConnection::closePeerConnection() {
qCDebug(networking_webrtc) << "WDCConnection::closePeerConnection() :" << (int)_peerConnection->peer_connection_state(); qCDebug(networking_webrtc) << "WDCConnection::closePeerConnection() :" << (int)_peerConnection->peer_connection_state();
#endif #endif
_peerConnection->Close(); _peerConnection->Close();
_peerConnection = nullptr; // Don't set _peerConnection = nullptr because it is a scoped_refptr.
_peerConnectionObserver = nullptr; _peerConnectionObserver = nullptr;
#ifdef WEBRTC_DEBUG #ifdef WEBRTC_DEBUG
qCDebug(networking_webrtc) << "Disposed of peer connection"; qCDebug(networking_webrtc) << "Disposed of peer connection";