1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(coreav): fix assert because c-toxcore calls from unexpected thread

c-toxcore calls the groupCallCallback from it's main thread instead of
the ToxAV thread as expected, this was triggering an assertion.

Aditionally the destructors of Core and CoreAV were fixed, because they
now either crashed or deadlocked qTox when it was closed while a group
call was still running.
This commit is contained in:
sudden6 2020-01-20 23:19:08 +01:00
parent 4b9e4a571d
commit 141cbf8870
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 20 additions and 4 deletions

View File

@ -484,12 +484,14 @@ Core::Core(QThread* coreThread)
Core::~Core()
{
// need to reset av first, because it uses tox
av.reset();
/*
* First stop the thread to stop the timer and avoid Core emitting callbacks
* into an already destructed CoreAV.
*/
coreThread->exit(0);
coreThread->wait();
av.reset();
tox.reset();
}

View File

@ -151,9 +151,16 @@ IAudioControl* CoreAV::getAudio()
CoreAV::~CoreAV()
{
/* Gracefully leave calls and group calls to avoid deadlocks in destructor */
for (const auto& call : calls) {
cancelCall(call.first);
}
for (const auto& call : groupCalls) {
leaveGroupCall(call.first);
}
assert(calls.empty());
assert(groupCalls.empty());
coreavThread->exit(0);
coreavThread->wait();
@ -452,12 +459,19 @@ void CoreAV::toggleMuteCallOutput(const Friend* f)
void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data,
unsigned samples, uint8_t channels, uint32_t sample_rate, void* core)
{
/*
* Currently group call audio decoding is handled in the Tox thread by c-toxcore,
* so we can be sure that this function is always called from the Core thread.
* To change this, an API change in c-toxcore is needed and this function probably must be
* changed.
* See https://github.com/TokTok/c-toxcore/issues/1364 for details.
*/
Q_UNUSED(tox);
Core* c = static_cast<Core*>(core);
CoreAV* cav = c->getAv();
QReadLocker locker{&cav->callsLock};
assert(QThread::currentThread() == cav->coreavThread.get());
const ToxPk peerPk = c->getGroupPeerPk(group, peer);
const Settings& s = Settings::getInstance();