mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix crash when freed friend gets inactivated
This commit is contained in:
parent
12886f1c45
commit
67f2367c9d
|
@ -34,3 +34,8 @@ qint64 AudioBuffer::bufferSize() const
|
|||
{
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
void AudioBuffer::clear()
|
||||
{
|
||||
buffer.clear();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
qint64 writeData(const char *data, qint64 len);
|
||||
qint64 bytesAvailable() const;
|
||||
qint64 bufferSize() const;
|
||||
void clear();
|
||||
|
||||
private:
|
||||
QByteArray buffer;
|
||||
|
|
4
core.cpp
4
core.cpp
|
@ -1056,17 +1056,19 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav)
|
|||
}
|
||||
else
|
||||
qDebug() << QString("Core: Audio started, buffer size %1").arg(calls[callId].audioOutput->bufferSize());
|
||||
QtConcurrent::run(playCallAudio, callId, toxav);
|
||||
calls[callId].playFuture = QtConcurrent::run(playCallAudio, callId, toxav);
|
||||
}
|
||||
|
||||
void Core::cleanupCall(int callId)
|
||||
{
|
||||
qDebug() << QString("Core: cleaning up call %1").arg(callId);
|
||||
calls[callId].active = false;
|
||||
calls[callId].playFuture.waitForFinished();
|
||||
if (calls[callId].audioOutput != nullptr)
|
||||
{
|
||||
delete calls[callId].audioOutput;
|
||||
}
|
||||
calls[callId].audioBuffer.clear();
|
||||
}
|
||||
|
||||
void Core::playCallAudio(int callId, ToxAv* toxav)
|
||||
|
|
1
core.h
1
core.h
|
@ -89,6 +89,7 @@ public:
|
|||
int callId;
|
||||
int friendId;
|
||||
bool active;
|
||||
QFuture<void> playFuture;
|
||||
};
|
||||
|
||||
class Core : public QObject
|
||||
|
|
|
@ -6,6 +6,9 @@ QList<Friend*> FriendList::friendList;
|
|||
|
||||
Friend* FriendList::addFriend(int friendId, QString userId)
|
||||
{
|
||||
for (Friend* f : friendList)
|
||||
if (f->friendId == friendId)
|
||||
qWarning() << "FriendList::addFriend: friendId already taken";
|
||||
Friend* newfriend = new Friend(friendId, userId);
|
||||
friendList.append(newfriend);
|
||||
return newfriend;
|
||||
|
|
18
main.cpp
18
main.cpp
|
@ -33,3 +33,21 @@ int main(int argc, char *argv[])
|
|||
* An extra side panel for groupchats, like Venom does (?)
|
||||
*
|
||||
*/
|
||||
|
||||
/** NAMES :
|
||||
Botox
|
||||
Ricin
|
||||
Anthrax
|
||||
Sarin
|
||||
Cyanide
|
||||
Polonium
|
||||
Mercury
|
||||
Arsenic
|
||||
qTox
|
||||
plague
|
||||
Britney
|
||||
Nightshade
|
||||
Belladonna
|
||||
toxer
|
||||
GoyIM
|
||||
*/
|
||||
|
|
|
@ -383,6 +383,8 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
|
|||
void Widget::removeFriend(int friendId)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
if (f->widget == activeFriendWidget)
|
||||
activeFriendWidget = nullptr;
|
||||
FriendList::removeFriend(friendId);
|
||||
core->removeFriend(friendId);
|
||||
delete f;
|
||||
|
@ -449,6 +451,8 @@ void Widget::onGroupWidgetClicked(GroupWidget* widget)
|
|||
void Widget::removeGroup(int groupId)
|
||||
{
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
if (g->widget == activeGroupWidget)
|
||||
activeGroupWidget == nullptr;
|
||||
GroupList::removeGroup(groupId);
|
||||
core->removeGroup(groupId);
|
||||
delete g;
|
||||
|
|
Loading…
Reference in New Issue
Block a user