diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp index d9ff1daac8..990b317b65 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp @@ -154,7 +154,7 @@ public: u32 end_address = address + static_cast(bytes.size()) - 1; AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_view->GetAddressSpace()); - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(m_view->m_system); if (!bytes.empty() && accessors->IsValidAddress(guard, address) && accessors->IsValidAddress(guard, end_address)) @@ -170,8 +170,8 @@ private: MemoryViewWidget* m_view; }; -MemoryViewWidget::MemoryViewWidget(QWidget* parent) - : QWidget(parent), m_system(Core::System::GetInstance()) +MemoryViewWidget::MemoryViewWidget(Core::System& system, QWidget* parent) + : QWidget(parent), m_system(system) { auto* layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); @@ -443,7 +443,7 @@ void MemoryViewWidget::UpdateColumns() if (Core::GetState() == Core::State::Paused) { - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(m_system); UpdateColumns(&guard); } else @@ -850,12 +850,8 @@ void MemoryViewWidget::OnCopyHex(u32 addr) { const auto length = GetTypeSize(m_type); - const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space); - - const u64 value = [addr, accessors] { - Core::CPUThreadGuard guard(Core::System::GetInstance()); - return accessors->ReadU64(guard, addr); - }(); + const u64 value = + AddressSpace::GetAccessors(m_address_space)->ReadU64(Core::CPUThreadGuard{m_system}, addr); QApplication::clipboard()->setText( QStringLiteral("%1").arg(value, sizeof(u64) * 2, 16, QLatin1Char('0')).left(length * 2)); @@ -873,12 +869,8 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos) const u32 addr = item_selected->data(USER_ROLE_CELL_ADDRESS).toUInt(); const bool item_has_value = item_selected->data(USER_ROLE_VALUE_TYPE).toInt() != static_cast(Type::Null) && - [this, addr] { - const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space); - - Core::CPUThreadGuard guard(Core::System::GetInstance()); - return accessors->IsValidAddress(guard, addr); - }(); + AddressSpace::GetAccessors(m_address_space) + ->IsValidAddress(Core::CPUThreadGuard{m_system}, addr); auto* menu = new QMenu(this); diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h index c958ede341..1ae6106154 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h @@ -53,7 +53,7 @@ public: WriteOnly }; - explicit MemoryViewWidget(QWidget* parent = nullptr); + explicit MemoryViewWidget(Core::System& system, QWidget* parent = nullptr); void CreateTable(); void Update(); diff --git a/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp index 3910d093aa..9b2fba6d29 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp @@ -40,7 +40,8 @@ using Type = MemoryViewWidget::Type; -MemoryWidget::MemoryWidget(QWidget* parent) : QDockWidget(parent) +MemoryWidget::MemoryWidget(Core::System& system, QWidget* parent) + : QDockWidget(parent), m_system(system) { setWindowTitle(tr("Memory")); setObjectName(QStringLiteral("memory")); @@ -287,7 +288,7 @@ void MemoryWidget::CreateWidgets() sidebar_scroll->setWidget(sidebar); sidebar_scroll->setWidgetResizable(true); - m_memory_view = new MemoryViewWidget(this); + m_memory_view = new MemoryViewWidget(m_system, this); m_splitter->addWidget(m_memory_view); m_splitter->addWidget(sidebar_scroll); @@ -496,7 +497,7 @@ void MemoryWidget::SetAddress(u32 address) AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(m_system); good = accessors->IsValidAddress(guard, current_addr); } @@ -653,7 +654,7 @@ void MemoryWidget::OnSetValue() return; } - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(m_system); AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); u32 end_address = target_addr.address + static_cast(bytes.size()) - 1; @@ -715,7 +716,7 @@ void MemoryWidget::OnSetValueFromFile() AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(m_system); for (u8 b : file_contents) accessors->WriteU8(guard, target_addr.address++, b); @@ -833,7 +834,7 @@ void MemoryWidget::FindValue(bool next) AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); - Core::CPUThreadGuard guard(Core::System::GetInstance()); + const Core::CPUThreadGuard guard(m_system); return accessors->Search(guard, target_addr.address, reinterpret_cast(search_for.data()), static_cast(search_for.size()), next); diff --git a/Source/Core/DolphinQt/Debugger/MemoryWidget.h b/Source/Core/DolphinQt/Debugger/MemoryWidget.h index ef6be33e59..d50610ac12 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryWidget.h +++ b/Source/Core/DolphinQt/Debugger/MemoryWidget.h @@ -22,14 +22,15 @@ class QSplitter; namespace Core { +class System; class CPUThreadGuard; -} +} // namespace Core class MemoryWidget : public QDockWidget { Q_OBJECT public: - explicit MemoryWidget(QWidget* parent = nullptr); + explicit MemoryWidget(Core::System& system, QWidget* parent = nullptr); ~MemoryWidget(); void SetAddress(u32 address); @@ -78,6 +79,8 @@ private: void closeEvent(QCloseEvent*) override; void showEvent(QShowEvent* event) override; + Core::System& m_system; + MemoryViewWidget* m_memory_view; QSplitter* m_splitter; QComboBox* m_search_address; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 54b75c05c1..a76fd36b55 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -449,7 +449,7 @@ void MainWindow::CreateComponents() m_jit_widget = new JITWidget(this); m_log_widget = new LogWidget(this); m_log_config_widget = new LogConfigWidget(this); - m_memory_widget = new MemoryWidget(this); + m_memory_widget = new MemoryWidget(Core::System::GetInstance(), this); m_network_widget = new NetworkWidget(this); m_register_widget = new RegisterWidget(this); m_thread_widget = new ThreadWidget(this);