This PR addresses the remaining crash issues in GitHub issue #7478 where closing multiple profiles simultaneously could cause crashes due to Qt widgets being accessed during destruction.
When rapidly closing multiple profiles (e.g., using Alt+W to close 16 profiles quickly), Mudlet would crash with a stack trace pointing to:
QTextLayout::preeditAreaText()
TMainConsole::printOnDisplay()
at line 1182cTelnet::slot_socketDisconnected()
The crash occurred due to a race condition during widget destruction:
Host::closeChildren()
called → mIsClosingDown = true
cTelnet::slot_socketDisconnected()
→ postData()
→ TMainConsole::printOnDisplay()
mpLineEdit_networkLatency->setText()
QTextLayout
is already destroyedsetText()
tries to access destroyed memory → segmentation faultThe issue was that null pointer checks alone are insufficient - Qt widgets can have valid pointers while their internal components are destroyed.
Instead of masking the problem with exception handling, this fix prevents unsafe widget access by using Qt’s built-in widget lifecycle indicators.
// Before (vulnerable):
if (mpLineEdit_networkLatency && !mpHost->isClosingDown()) {
mpLineEdit_networkLatency->setText(...); // CRASH - widget internals destroyed
}
// After (safe):
if (mpLineEdit_networkLatency && !mpHost->isClosingDown()) {
QWidget* parentWidget = mpLineEdit_networkLatency->parentWidget();
if (parentWidget && mpLineEdit_networkLatency->isVisible()) {
mpLineEdit_networkLatency->setText(...); // SAFE - widget fully intact
}
}
// Before (vulnerable):
mpHost->mpConsole->printOnDisplay(mMudData, true); // Could crash
// After (safe):
QWidget* parentWidget = mpHost->mpConsole->parentWidget();
if (!parentWidget || !mpHost->mpConsole->isVisible()) {
return; // Skip if console is being destroyed
}
mpHost->mpConsole->printOnDisplay(mMudData, true); // Safe to proceed
Qt destroys widgets in a specific order:
parentWidget()
→ null)isVisible()
→ false)By checking both parentWidget()
and isVisible()
, we can reliably detect when a widget is in the destruction process and avoid accessing it entirely.
/claim #7478.
Rishi Mondal
@MAVRICK-1
Mudlet
@Mudlet