Fixed HexViewerItem pointer invalidation bug

This commit is contained in:
Nav
2023-03-09 20:46:26 +00:00
parent e83ce7de8f
commit d1e7b900de
4 changed files with 35 additions and 15 deletions

View File

@@ -76,6 +76,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.cpp

View File

@@ -20,6 +20,12 @@ namespace Bloom::Widgets
this->setCacheMode(QGraphicsItem::CacheMode::NoCache);
}
~GraphicsItem() {
if (this->hexViewerItem != nullptr) {
this->hexViewerItem->allocatedGraphicsItem = nullptr;
}
}
void setHexViewerItem(HexViewerItem* item) {
if (this->hexViewerItem != nullptr) {
this->hexViewerItem->allocatedGraphicsItem = nullptr;

View File

@@ -0,0 +1,25 @@
#include "HexViewerItem.hpp"
#include "GraphicsItem.hpp"
namespace Bloom::Widgets
{
HexViewerItem::HexViewerItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent)
: startAddress(startAddress)
, parent(parent)
{}
HexViewerItem::~HexViewerItem() {
if (this->allocatedGraphicsItem != nullptr) {
this->allocatedGraphicsItem->setHexViewerItem(nullptr);
}
}
QPoint HexViewerItem::position() const {
if (this->parent != nullptr) {
return this->parent->position() + this->relativePosition;
}
return this->relativePosition;
}
}

View File

@@ -25,23 +25,11 @@ namespace Bloom::Widgets
HexViewerItem* parent = nullptr;
GraphicsItem* allocatedGraphicsItem = nullptr;
HexViewerItem(
Targets::TargetMemoryAddress startAddress,
HexViewerItem* parent = nullptr
)
: startAddress(startAddress)
, parent(parent)
{};
HexViewerItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent = nullptr);
virtual ~HexViewerItem() = default;
virtual ~HexViewerItem();
QPoint position() const {
if (this->parent != nullptr) {
return this->parent->position() + this->relativePosition;
}
return this->relativePosition;
}
QPoint position() const;
virtual QSize size() const = 0;