From 889b4377755044ef0b3c76e35b217f3b3626d628 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 20 Apr 2023 13:15:31 -0700 Subject: [PATCH] Qt add_menu() w/o start_menu() I temporarily reverted the fix for end-of-game disclosure of overview in order to trigger the add_menu() crash under Qt. It came down to if (!actual) impossible("AddMenu called before we know if Menu or Text"); actual->AddMenu(glyph,identifier,ch,gch,attr,str,itemflags); where 'actual' happens to be Null. impossible() gets called, goes through pline() calling putmesg() and putstr(WIN_MESSAGE), then the output never shows up anywhere. I haven't figured our what's going on with that, but changing the above to if (!actual) impossible("AddMenu called before we know if Menu or Text"); else actual->AddMenu(glyph, identifier, ch, gch, attr, str, itemflags); at least prevents the crash. The main window ends up becoming minimized/iconified but the final popups which occur after disclosure appear and accept responses and then a clean exit takes place. Presumably it used panic() rather than impossible() at some point, otherwise that code makes no sense: test for Null then deference it regardless of the result of the test? --- win/Qt/qt_menu.cpp | 48 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/win/Qt/qt_menu.cpp b/win/Qt/qt_menu.cpp index d8794086f..441113189 100644 --- a/win/Qt/qt_menu.cpp +++ b/win/Qt/qt_menu.cpp @@ -1286,25 +1286,37 @@ NetHackQtMenuOrTextWindow::NetHackQtMenuOrTextWindow(QWidget *parent_) : QWidget* NetHackQtMenuOrTextWindow::Widget() { - if (!actual) impossible("Widget called before we know if Menu or Text"); - return actual->Widget(); + QWidget *result = NULL; + if (!actual) + impossible("Widget called before we know if Menu or Text"); + else + result = actual->Widget(); + return result; } // Text void NetHackQtMenuOrTextWindow::Clear() { - if (!actual) impossible("Clear called before we know if Menu or Text"); - actual->Clear(); + if (!actual) + impossible("Clear called before we know if Menu or Text"); + else + actual->Clear(); } void NetHackQtMenuOrTextWindow::Display(bool block) { - if (!actual) impossible("Display called before we know if Menu or Text"); - actual->Display(block); + if (!actual) + impossible("Display called before we know if Menu or Text"); + else + actual->Display(block); } bool NetHackQtMenuOrTextWindow::Destroy() { - if (!actual) impossible("Destroy called before we know if Menu or Text"); - return actual->Destroy(); + bool result = false; + if (!actual) + impossible("Destroy called before we know if Menu or Text"); + else + result = actual->Destroy(); + return result; } void NetHackQtMenuOrTextWindow::PutStr(int attr, const QString& text) @@ -1323,18 +1335,26 @@ void NetHackQtMenuOrTextWindow::AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr, const QString& str, unsigned itemflags) { - if (!actual) impossible("AddMenu called before we know if Menu or Text"); - actual->AddMenu(glyph,identifier,ch,gch,attr,str,itemflags); + if (!actual) + impossible("AddMenu called before we know if Menu or Text"); + else + actual->AddMenu(glyph, identifier, ch, gch, attr, str, itemflags); } void NetHackQtMenuOrTextWindow::EndMenu(const QString& prompt) { - if (!actual) impossible("EndMenu called before we know if Menu or Text"); - actual->EndMenu(prompt); + if (!actual) + impossible("EndMenu called before we know if Menu or Text"); + else + actual->EndMenu(prompt); } int NetHackQtMenuOrTextWindow::SelectMenu(int how, MENU_ITEM_P **menu_list) { - if (!actual) impossible("SelectMenu called before we know if Menu or Text"); - return actual->SelectMenu(how,menu_list); + int result = -1; + if (!actual) + impossible("SelectMenu called before we know if Menu or Text"); + else + result = actual->SelectMenu(how, menu_list); + return result; } } // namespace nethack_qt_