Turns out we can't construct a QGraphicsScene on a different thread - causes issues with Qt's internal event posting code.

Instead, we now construct just the ByteItem objects on the worker thread. At some point, I'd like to move the item positioning onto
a worker thread, but that's for another day.
This commit is contained in:
Nav
2022-09-13 22:40:55 +01:00
parent 59986b052a
commit 9aff8183dd
11 changed files with 139 additions and 122 deletions

View File

@@ -1,32 +0,0 @@
#include "ConstructHexViewerByteItemScene.hpp"
namespace Bloom
{
ConstructHexViewerByteItemScene::ConstructHexViewerByteItemScene(
const Targets::TargetMemoryDescriptor& memoryDescriptor,
std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
Widgets::HexViewerWidgetSettings& settings,
Widgets::Label* hoveredAddressLabel
)
: memoryDescriptor(memoryDescriptor)
, focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions)
, settings(settings)
, hoveredAddressLabel(hoveredAddressLabel)
{}
void ConstructHexViewerByteItemScene::run(TargetController::TargetControllerConsole&) {
auto* scene = new Widgets::ByteItemGraphicsScene(
this->memoryDescriptor,
this->focusedMemoryRegions,
this->excludedMemoryRegions,
this->settings,
this->hoveredAddressLabel,
nullptr
);
scene->moveToThread(nullptr);
emit this->sceneCreated(scene);
}
}

View File

@@ -0,0 +1,41 @@
#include "ConstructHexViewerByteItems.hpp"
namespace Bloom
{
ConstructHexViewerByteItems::ConstructHexViewerByteItems(
const Targets::TargetMemoryDescriptor& memoryDescriptor,
std::optional<Targets::TargetStackPointer>& currentStackPointer,
Widgets::ByteItem** hoveredByteItem,
std::set<Widgets::ByteItem*>& highlightedByteItems,
Widgets::HexViewerWidgetSettings& settings
)
: memoryDescriptor(memoryDescriptor)
, currentStackPointer(currentStackPointer)
, hoveredByteItem(hoveredByteItem)
, highlightedByteItems(highlightedByteItems)
, settings(settings)
{}
void ConstructHexViewerByteItems::run(TargetController::TargetControllerConsole&) {
const auto memorySize = this->memoryDescriptor.size();
const auto startAddress = this->memoryDescriptor.addressRange.startAddress;
for (Targets::TargetMemorySize i = 0; i < memorySize; i++) {
const auto address = startAddress + i;
this->byteItemsByAddress.emplace(
address,
new Widgets::ByteItem(
i,
address,
this->currentStackPointer,
this->hoveredByteItem,
this->highlightedByteItems,
settings
)
);
}
emit this->byteItems(this->byteItemsByAddress);
}
}

View File

@@ -1,5 +1,8 @@
#pragma once
#include <optional>
#include <set>
#include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.hpp"
@@ -7,21 +10,22 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
namespace Bloom
{
class ConstructHexViewerByteItemScene: public InsightWorkerTask
class ConstructHexViewerByteItems: public InsightWorkerTask
{
Q_OBJECT
public:
ConstructHexViewerByteItemScene(
ConstructHexViewerByteItems(
const Targets::TargetMemoryDescriptor& memoryDescriptor,
std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
Widgets::HexViewerWidgetSettings& settings,
Widgets::Label* hoveredAddressLabel
std::optional<Targets::TargetStackPointer>& currentStackPointer,
Widgets::ByteItem** hoveredByteItem,
std::set<Widgets::ByteItem*>& highlightedByteItems,
Widgets::HexViewerWidgetSettings& settings
);
TaskGroups getTaskGroups() const override {
@@ -30,15 +34,18 @@ namespace Bloom
signals:
void sceneCreated(Widgets::ByteItemGraphicsScene* scene);
void byteItems(std::map<Targets::TargetMemoryAddress, Widgets::ByteItem*>& byteItemsByAddress);
protected:
void run(TargetController::TargetControllerConsole& targetControllerConsole) override;
void run(TargetController::TargetControllerConsole&) override;
private:
std::map<Targets::TargetMemoryAddress, Widgets::ByteItem*> byteItemsByAddress;
const Targets::TargetMemoryDescriptor& memoryDescriptor;
std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;
std::optional<Targets::TargetStackPointer>& currentStackPointer;
Widgets::ByteItem** hoveredByteItem;
std::set<Widgets::ByteItem*>& highlightedByteItems;
Widgets::HexViewerWidgetSettings& settings;
Widgets::Label* hoveredAddressLabel;
};
}