From 3fc805bc7d0e2b017ba95c92ea02387e167bce01 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 26 Aug 2023 12:04:52 +0300 Subject: fixes #3649 ([Tox] Caught a rare? crash during idle) --- protocols/Tox/src/tox_connection.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'protocols') diff --git a/protocols/Tox/src/tox_connection.cpp b/protocols/Tox/src/tox_connection.cpp index 56c1d7a901..3b0d3c9d46 100644 --- a/protocols/Tox/src/tox_connection.cpp +++ b/protocols/Tox/src/tox_connection.cpp @@ -22,11 +22,15 @@ void CToxProto::OnLoggedIn() LoadFriendList(m_tox); } -void CToxProto::OnLoggedFail() +///////////////////////////////////////////////////////////////////////////////////////// +// Tox polling callback + +static void sttScheduledDisconnect(void *param) { - SetStatus(ID_STATUS_OFFLINE); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK); - debugLogA(__FUNCTION__": failed to connect to DHT"); + auto *ppro = (CToxProto *)param; + ppro->SetStatus(ID_STATUS_OFFLINE); + ppro->ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK); + ppro->debugLogA(__FUNCTION__": failed to connect to DHT"); } void CToxProto::OnConnectionStatus(Tox*, Tox_Connection iNewStatus, void *pUserData) @@ -35,10 +39,11 @@ void CToxProto::OnConnectionStatus(Tox*, Tox_Connection iNewStatus, void *pUserD if (ppro->m_tox == nullptr) return; - if (iNewStatus == TOX_CONNECTION_NONE) - ppro->OnLoggedFail(); - else - ppro->OnLoggedIn(); + if (iNewStatus == TOX_CONNECTION_NONE) { + // we cannot destroy Tox object inside its hook... #3649 + Miranda_WaitOnHandleEx(sttScheduledDisconnect, ppro); + } + else ppro->OnLoggedIn(); } void CToxProto::OnToxPoll() -- cgit v1.2.3