diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index 0f7e3a02..2621d9f6 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -840,7 +841,7 @@ void NetPlayServer::processClientRomLoadRequests(void) { netPlayTextMsg<128> errorMsg(NETPLAY_ERROR_MSG); errorMsg.setFlag(netPlayTextMsgFlags::Warning); - errorMsg.printf("Host is rejected ROMs load request"); + errorMsg.printf("Host has rejected ROM load request"); sendMsg( client, &errorMsg, errorMsg.hdr.msgSize, [&errorMsg]{ errorMsg.toNetworkByteOrder(); } ); } @@ -1127,6 +1128,11 @@ NetPlayClient::~NetPlayClient(void) { ::free(recvMsgBuf); recvMsgBuf = nullptr; } + + if (numMsgBoxObjs != 0) + { + printf("Warning: Client has leaked message dialogs\n"); + } printf("NetPlayClient Destructor\n"); } @@ -1611,9 +1617,15 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) msg->toHostByteOrder(); FCEU_printf("NetPlay Error: %s\n", msg->getBuffer()); - QString msgBoxTxt = tr("Host has replied with an error:\n\n"); + numMsgBoxObjs++; + QString msgBoxTxt = tr("Host has replied with an error:\n\n"); msgBoxTxt += tr(msg->getBuffer()); - QMessageBox::critical( consoleWindow, tr("NetPlay Error"), msgBoxTxt, QMessageBox::Ok ); + + QMessageBox* msgBox = new QMessageBox( QMessageBox::Critical, tr("NetPlay Error"), msgBoxTxt, QMessageBox::Ok, consoleWindow ); + connect( msgBox->button(QMessageBox::Ok), SIGNAL(clicked(void)), msgBox, SLOT(accept(void))); + connect( msgBox, &QMessageBox::finished, this, [this, msgBox](){ msgBox->deleteLater(); } ); + connect( msgBox, SIGNAL(destroyed(QObject*)), this, SLOT(onMessageBoxDestroy(QObject*))); + msgBox->show(); if (msg->isFlagSet(netPlayTextMsgFlags::Disconnect)) { @@ -1743,6 +1755,19 @@ void NetPlayClient::clientReadyRead() readMessages( clientMessageCallback, this ); } //----------------------------------------------------------------------------- +void NetPlayClient::onMessageBoxDestroy(QObject* obj) +{ + //printf("MessageBox Destroyed: %p\n", obj); + if (numMsgBoxObjs > 0) + { + numMsgBoxObjs--; + } + else + { + printf("Warning: Unexpected MessageBox Destroy: %p\n", obj); + } +} +//----------------------------------------------------------------------------- //--- NetPlayHostDialog //----------------------------------------------------------------------------- NetPlayHostDialog* NetPlayHostDialog::instance = nullptr; diff --git a/src/drivers/Qt/NetPlay.h b/src/drivers/Qt/NetPlay.h index 67c02a2d..d41f6e35 100644 --- a/src/drivers/Qt/NetPlay.h +++ b/src/drivers/Qt/NetPlay.h @@ -327,6 +327,7 @@ class NetPlayClient : public QObject uint64_t pingDelayLast = 0; uint64_t pingNumSamples = 0; uint32_t romCrc32 = 0; + uint32_t numMsgBoxObjs = 0; std::list input; FCEU::mutex inputMtx; @@ -345,6 +346,7 @@ class NetPlayClient : public QObject void onRomUnload(void); void serverReadyRead(void); void clientReadyRead(void); + void onMessageBoxDestroy(QObject* obj); };