Browse Source

Fix crash when freed friend gets inactivated

pull/9/merge
Tux3 / Mlkj / !Lev.uXFMLA 11 years ago
parent
commit
67f2367c9d
  1. 5
      audiobuffer.cpp
  2. 1
      audiobuffer.h
  3. 4
      core.cpp
  4. 1
      core.h
  5. 3
      friendlist.cpp
  6. 18
      main.cpp
  7. 4
      widget/widget.cpp

5
audiobuffer.cpp

@ -34,3 +34,8 @@ qint64 AudioBuffer::bufferSize() const @@ -34,3 +34,8 @@ qint64 AudioBuffer::bufferSize() const
{
return buffer.size();
}
void AudioBuffer::clear()
{
buffer.clear();
}

1
audiobuffer.h

@ -15,6 +15,7 @@ public: @@ -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

@ -1056,17 +1056,19 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav) @@ -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

@ -89,6 +89,7 @@ public: @@ -89,6 +89,7 @@ public:
int callId;
int friendId;
bool active;
QFuture<void> playFuture;
};
class Core : public QObject

3
friendlist.cpp

@ -6,6 +6,9 @@ QList<Friend*> FriendList::friendList; @@ -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

@ -33,3 +33,21 @@ int main(int argc, char *argv[]) @@ -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
*/

4
widget/widget.cpp

@ -383,6 +383,8 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa @@ -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) @@ -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…
Cancel
Save