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

@ -25,7 +25,7 @@ namespace NetPlay
{
class NetPlayClient;
class NetPlayServer;
}
} // namespace NetPlay
class GameListModel;
class InputConfig;
@ -98,9 +98,9 @@ public:
void DecreaseVolume(int volume);
// NetPlay
NetPlay::NetPlayClient* GetNetPlayClient();
std::shared_ptr<NetPlay::NetPlayClient> GetNetPlayClient();
void ResetNetPlayClient(NetPlay::NetPlayClient* client = nullptr);
NetPlay::NetPlayServer* GetNetPlayServer();
std::shared_ptr<NetPlay::NetPlayServer> GetNetPlayServer();
void ResetNetPlayServer(NetPlay::NetPlayServer* server = nullptr);
// Cheats
@ -169,8 +169,8 @@ signals:
private:
bool m_batch = false;
bool m_controller_state_needed = false;
std::unique_ptr<NetPlay::NetPlayClient> m_client;
std::unique_ptr<NetPlay::NetPlayServer> m_server;
std::shared_ptr<NetPlay::NetPlayClient> m_client;
std::shared_ptr<NetPlay::NetPlayServer> m_server;
Settings();
};