From 7b70fd0008f95e17e9e81e7d85738a63bca5e35b Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Sat, 25 Oct 2014 11:29:25 +0200 Subject: [PATCH] Fix crash if call failed to start --- src/core.h | 1 + src/coreav.cpp | 25 +++++++++++++++++++++---- src/widget/form/chatform.cpp | 12 ++++++++++++ src/widget/form/chatform.h | 1 + src/widget/widget.cpp | 1 + 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/core.h b/src/core.h index f197f066a..cf38f3280 100644 --- a/src/core.h +++ b/src/core.h @@ -185,6 +185,7 @@ signals: void avRequestTimeout(int friendId, int callIndex); void avPeerTimeout(int friendId, int callIndex); void avMediaChange(int friendId, int callIndex, bool videoEnabled); + void avCallFailed(int friendId); void videoFrameReceived(vpx_image* frame); diff --git a/src/coreav.cpp b/src/coreav.cpp index 1476acefa..85ee84ee5 100644 --- a/src/coreav.cpp +++ b/src/coreav.cpp @@ -142,15 +142,32 @@ void Core::startCall(int friendId, bool video) { qDebug() << QString("Core: Starting new call with %1 with video").arg(friendId); cSettings.call_type = TypeVideo; - toxav_call(toxav, &callId, friendId, &cSettings, TOXAV_RINGING_TIME); - calls[callId].videoEnabled=true; + if (toxav_call(toxav, &callId, friendId, &cSettings, TOXAV_RINGING_TIME) == 0) + { + calls[callId].videoEnabled=true; + } + else + { + qWarning() << QString("Core: Failed to start new video call with %1").arg(friendId); + emit avCallFailed(friendId); + return; + } } else { qDebug() << QString("Core: Starting new call with %1 without video").arg(friendId); cSettings.call_type = TypeAudio; - toxav_call(toxav, &callId, friendId, &cSettings, TOXAV_RINGING_TIME); - calls[callId].videoEnabled=false; + if (toxav_call(toxav, &callId, friendId, &cSettings, TOXAV_RINGING_TIME) == 0) + { + calls[callId].videoEnabled=false; + } + else + { + qWarning() << QString("Core: Failed to start new audio call with %1").arg(friendId); + emit avCallFailed(friendId); + return; + } + } } diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 9bb18e46d..a4e62bf49 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -459,6 +459,18 @@ void ChatForm::onVideoCallTriggered() emit startVideoCall(f->friendId, true); } +void ChatForm::onAvCallFailed(int FriendId) +{ + if (FriendId != f->friendId) + return; + + audioInputFlag = false; + callButton->disconnect(); + videoButton->disconnect(); + connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered())); + connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered())); +} + void ChatForm::onCancelCallTriggered() { audioInputFlag = false; diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index fd33a33a0..dea18e8b7 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -55,6 +55,7 @@ public slots: void onAvRequestTimeout(int FriendId, int CallId); void onAvPeerTimeout(int FriendId, int CallId); void onAvMediaChange(int FriendId, int CallId, bool video); + void onAvCallFailed(int FriendId); void onMicMuteToggle(); void onAvatarChange(int FriendId, const QPixmap& pic); void onAvatarRemoved(int FriendId); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 27f54f6df..1066803cf 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -620,6 +620,7 @@ void Widget::addFriend(int friendId, const QString &userId) connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout); connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout); connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange); + connect(core, &Core::avCallFailed, newfriend->chatForm, &ChatForm::onAvCallFailed); connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange); connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange); connect(core, &Core::friendAvatarRemoved, newfriend->chatForm, &ChatForm::onAvatarRemoved);