From 19bbd4d6d99e387a79fb8e51fd582b80e6543953 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sun, 26 Jan 2025 23:35:45 -0500 Subject: [PATCH] fix crash when deleting TGID causes the TG list to scroll; --- src/tged/TGListWnd.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tged/TGListWnd.h b/src/tged/TGListWnd.h index 8854a073..4e4fc299 100644 --- a/src/tged/TGListWnd.h +++ b/src/tged/TGListWnd.h @@ -316,6 +316,23 @@ class HOST_SW_API TGListWnd final : public FDblDialog { LogMessage(LOG_HOST, "Deleting TG %s (%u)", m_selected.name().c_str(), m_selected.source().tgId()); g_tidLookups->eraseEntry(m_selected.source().tgId(), m_selected.source().tgSlot()); + + // bryanb: HACK -- use HackTheGibson to access the private current listview iterator to get the scroll position + /* + * This uses the RTTI hack to access private members on FListView; and this code *could* break as a consequence. + */ + int firstScrollLinePos = 0; + if (m_listView.getCount() > 0) { + firstScrollLinePos = (m_listView.*RTTIResult::ptr).getPosition(); + } + if ((size_t)firstScrollLinePos > m_listView.getCount()) + firstScrollLinePos = 0; + if (firstScrollLinePos > 0 && m_listView.getCount() > 0) { + --firstScrollLinePos; + (m_listView.*RTTIResult::ptr)(firstScrollLinePos); + (m_listView.*RTTIResult::ptr)->setValue(firstScrollLinePos); + } + loadListView(); }