(Hopefully) fix memory corruption bug in QPlainTextEdit if setting invalid text cursor
MODIFY
src/programviewer.cpp
src/programviewer.cpp
@@ -55,6 +55,7 @@ void ProgramViewer::updateProgram(bool binary) {
// but seems to be fixed if we manually clear the selections before we clear (and add new text) to the text
// edit.
setExtraSelections({});
+ setTextCursor(QTextCursor());
setPlainText(text);
updateHighlightedAddresses();
@@ -76,10 +77,13 @@ void ProgramViewer::updateSidebarWidth(int /* newBlockCount */) {
void ProgramViewer::setCenterAddress(const long address) {
auto block = blockForAddress(address);
if (block.isValid()) {
- setTextCursor(QTextCursor(block));
+ auto newCursor = QTextCursor(block);
+ if (newCursor.blockNumber() != 0) {
+ setTextCursor(newCursor);
ensureCursorVisible();
}
}
+}
void ProgramViewer::updateCenterAddressFromProcessor() {
const auto stageInfo = ProcessorHandler::getProcessor()->stageInfo(0);

(Hopefully) fix memory corruption bug in QPlainTextEdit if setting invalid text cursor