From ff72b422b30a2b6d4b19cfc289eced6b3fe1b122 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 3 Sep 2021 19:04:24 +1200 Subject: [PATCH] Fix WebRTCDataChannels crash --- libraries/networking/src/webrtc/WebRTCDataChannels.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp index 3f7b84086d..c2b7ac6f5b 100644 --- a/libraries/networking/src/webrtc/WebRTCDataChannels.cpp +++ b/libraries/networking/src/webrtc/WebRTCDataChannels.cpp @@ -524,8 +524,14 @@ bool WebRTCDataChannels::sendDataMessage(int dataChannelID, const QByteArray& by /// @brief Gets the number of bytes waiting to be written on a data channel. /// @param port The data channel ID. -/// @return The number of bytes waiting to be written on the data channel. +/// @return The number of bytes waiting to be written on the data channel; 0 if the channel doesn't exist. qint64 WebRTCDataChannels::getBufferedAmount(int dataChannelID) const { + if (!_connectionsByDataChannel.contains(dataChannelID)) { +#ifdef WEBRTC_DEBUG + qCDebug(networking_webrtc) << "WebRTCDataChannels::getBufferedAmount() : Channel doesn't exist:" << dataChannelID; +#endif + return 0; + } auto connection = _connectionsByDataChannel.value(dataChannelID); return connection->getBufferedAmount(); }