Fix more segfaults on NetPlay quit

Basically everything here was race conditions in Qt callbacks, so I changed the client/server instances to std::shared_ptr and added null checks. It checks that the object exists in the callback, and the shared_ptr ensures it doesn't get destroyed until we're done with it.

MD5 check would also cause a segfault if you quit without cancelling it first, which was pretty silly.
This commit is contained in:
Techjar
2018-07-12 20:37:12 -04:00
parent a21d536f99
commit cfeffdcf42
7 changed files with 48 additions and 29 deletions

View File

@ -70,6 +70,10 @@ NetPlayClient::~NetPlayClient()
if (m_is_connected)
{
m_should_compute_MD5 = false;
m_dialog->AbortMD5();
if (m_MD5_thread.joinable())
m_MD5_thread.join();
m_do_loop.Clear();
m_thread.join();
}
@ -1636,12 +1640,14 @@ void NetPlayClient::ComputeMD5(const std::string& file_identifier)
return;
}
if (m_MD5_thread.joinable())
m_MD5_thread.join();
m_MD5_thread = std::thread([this, file]() {
std::string sum = MD5::MD5Sum(file, [&](int progress) {
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_MD5_PROGRESS);
packet << progress;
Send(packet);
SendAsync(std::move(packet));
return m_should_compute_MD5;
});
@ -1649,9 +1655,8 @@ void NetPlayClient::ComputeMD5(const std::string& file_identifier)
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_MD5_RESULT);
packet << sum;
Send(packet);
SendAsync(std::move(packet));
});
m_MD5_thread.detach();
}
const PadMappingArray& NetPlayClient::GetPadMapping() const