summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authormitaclaw <140017135+mitaclaw@users.noreply.github.com>2024-03-01 08:07:13 -0800
committermitaclaw <140017135+mitaclaw@users.noreply.github.com>2024-03-11 20:51:15 -0700
commitc377c1e21ea64435a4e0fb2d08c03cabb4ec981d (patch)
treeb3aac8d453a6e3d7648de616183db6541eb49d05 /Source
parent551dcec0b147b8d5c9828017edfde64ca9b90594 (diff)
CheatsManager/CheatSearchWidget: Avoid Global System Accessor
OnResetClicked and GenerateARCode appear to have been using the CPUThreadGuard in error.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/DolphinQt/CheatSearchWidget.cpp23
-rw-r--r--Source/Core/DolphinQt/CheatSearchWidget.h10
-rw-r--r--Source/Core/DolphinQt/CheatsManager.cpp5
-rw-r--r--Source/Core/DolphinQt/CheatsManager.h7
-rw-r--r--Source/Core/DolphinQt/MainWindow.cpp2
5 files changed, 28 insertions, 19 deletions
diff --git a/Source/Core/DolphinQt/CheatSearchWidget.cpp b/Source/Core/DolphinQt/CheatSearchWidget.cpp
index 020c7607a1..a76373238e 100644
--- a/Source/Core/DolphinQt/CheatSearchWidget.cpp
+++ b/Source/Core/DolphinQt/CheatSearchWidget.cpp
@@ -54,8 +54,10 @@ constexpr int ADDRESS_TABLE_COLUMN_INDEX_ADDRESS = 1;
constexpr int ADDRESS_TABLE_COLUMN_INDEX_LAST_VALUE = 2;
constexpr int ADDRESS_TABLE_COLUMN_INDEX_CURRENT_VALUE = 3;
-CheatSearchWidget::CheatSearchWidget(std::unique_ptr<Cheats::CheatSearchSessionBase> session)
- : m_session(std::move(session))
+CheatSearchWidget::CheatSearchWidget(Core::System& system,
+ std::unique_ptr<Cheats::CheatSearchSessionBase> session,
+ QWidget* parent)
+ : QWidget(parent), m_system(system), m_session(std::move(session))
{
setAttribute(Qt::WA_DeleteOnClose);
CreateWidgets();
@@ -275,13 +277,10 @@ void CheatSearchWidget::ConnectWidgets()
void CheatSearchWidget::OnNextScanClicked()
{
- Core::CPUThreadGuard guard(Core::System::GetInstance());
const bool had_old_results = m_session->WasFirstSearchDone();
- const size_t old_count = m_session->GetResultCount();
const auto filter_type = m_value_source_dropdown->currentData().value<Cheats::FilterType>();
- if (filter_type == Cheats::FilterType::CompareAgainstLastValue &&
- !m_session->WasFirstSearchDone())
+ if (filter_type == Cheats::FilterType::CompareAgainstLastValue && !had_old_results)
{
m_info_label_1->setText(tr("Cannot compare against last value on first search."));
return;
@@ -301,7 +300,8 @@ void CheatSearchWidget::OnNextScanClicked()
}
}
- const Cheats::SearchErrorCode error_code = m_session->RunSearch(guard);
+ const size_t old_count = m_session->GetResultCount();
+ const Cheats::SearchErrorCode error_code = m_session->RunSearch(Core::CPUThreadGuard{m_system});
if (error_code == Cheats::SearchErrorCode::Success)
{
@@ -416,11 +416,11 @@ void CheatSearchWidget::UpdateTableVisibleCurrentValues(const UpdateSource sourc
if (source == UpdateSource::Auto && !m_autoupdate_current_values->isChecked())
return;
- Core::CPUThreadGuard guard(Core::System::GetInstance());
if (m_address_table->rowCount() == 0)
return;
- UpdateTableRows(guard, GetVisibleRowsBeginIndex(), GetVisibleRowsEndIndex(), source);
+ UpdateTableRows(Core::CPUThreadGuard{m_system}, GetVisibleRowsBeginIndex(),
+ GetVisibleRowsEndIndex(), source);
}
bool CheatSearchWidget::UpdateTableAllCurrentValues(const UpdateSource source)
@@ -428,7 +428,6 @@ bool CheatSearchWidget::UpdateTableAllCurrentValues(const UpdateSource source)
if (source == UpdateSource::Auto && !m_autoupdate_current_values->isChecked())
return false;
- Core::CPUThreadGuard guard(Core::System::GetInstance());
const size_t result_count = m_address_table->rowCount();
if (result_count == 0)
{
@@ -437,7 +436,7 @@ bool CheatSearchWidget::UpdateTableAllCurrentValues(const UpdateSource source)
return false;
}
- return UpdateTableRows(guard, 0, result_count, source);
+ return UpdateTableRows(Core::CPUThreadGuard{m_system}, 0, result_count, source);
}
void CheatSearchWidget::OnRefreshClicked()
@@ -447,7 +446,6 @@ void CheatSearchWidget::OnRefreshClicked()
void CheatSearchWidget::OnResetClicked()
{
- Core::CPUThreadGuard guard(Core::System::GetInstance());
m_session->ResetResults();
m_address_table_current_values.clear();
@@ -525,7 +523,6 @@ void CheatSearchWidget::OnDisplayHexCheckboxStateChanged()
void CheatSearchWidget::GenerateARCode()
{
- Core::CPUThreadGuard guard(Core::System::GetInstance());
if (m_address_table->selectedItems().isEmpty())
return;
diff --git a/Source/Core/DolphinQt/CheatSearchWidget.h b/Source/Core/DolphinQt/CheatSearchWidget.h
index 5c3ad52423..5828c0423d 100644
--- a/Source/Core/DolphinQt/CheatSearchWidget.h
+++ b/Source/Core/DolphinQt/CheatSearchWidget.h
@@ -18,6 +18,10 @@ namespace ActionReplay
{
struct ARCode;
}
+namespace Core
+{
+class System;
+}
class QCheckBox;
class QComboBox;
@@ -36,7 +40,9 @@ class CheatSearchWidget : public QWidget
{
Q_OBJECT
public:
- explicit CheatSearchWidget(std::unique_ptr<Cheats::CheatSearchSessionBase> session);
+ explicit CheatSearchWidget(Core::System& system,
+ std::unique_ptr<Cheats::CheatSearchSessionBase> session,
+ QWidget* parent = nullptr);
~CheatSearchWidget() override;
enum class UpdateSource
@@ -74,6 +80,8 @@ private:
int GetVisibleRowsBeginIndex() const;
int GetVisibleRowsEndIndex() const;
+ Core::System& m_system;
+
std::unique_ptr<Cheats::CheatSearchSessionBase> m_session;
// storage for the 'Current Value' column's data
diff --git a/Source/Core/DolphinQt/CheatsManager.cpp b/Source/Core/DolphinQt/CheatsManager.cpp
index 8f2725b4a9..1af4d89197 100644
--- a/Source/Core/DolphinQt/CheatsManager.cpp
+++ b/Source/Core/DolphinQt/CheatsManager.cpp
@@ -24,7 +24,8 @@
#include "VideoCommon/VideoEvents.h"
-CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent)
+CheatsManager::CheatsManager(Core::System& system, QWidget* parent)
+ : QDialog(parent), m_system(system)
{
setWindowTitle(tr("Cheats Manager"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
@@ -169,7 +170,7 @@ void CheatsManager::CreateWidgets()
void CheatsManager::OnNewSessionCreated(const Cheats::CheatSearchSessionBase& session)
{
- auto* w = new CheatSearchWidget(session.Clone());
+ auto* w = new CheatSearchWidget(m_system, session.Clone());
const int tab_index = m_tab_widget->addTab(w, tr("Cheat Search"));
w->connect(w, &CheatSearchWidget::ActionReplayCodeGenerated, this,
[this](const ActionReplay::ARCode& ar_code) {
diff --git a/Source/Core/DolphinQt/CheatsManager.h b/Source/Core/DolphinQt/CheatsManager.h
index 33b61a4ccc..783a79ef45 100644
--- a/Source/Core/DolphinQt/CheatsManager.h
+++ b/Source/Core/DolphinQt/CheatsManager.h
@@ -26,13 +26,14 @@ class PartiallyClosableTabWidget;
namespace Core
{
enum class State;
-}
+class System;
+} // namespace Core
class CheatsManager : public QDialog
{
Q_OBJECT
public:
- explicit CheatsManager(QWidget* parent = nullptr);
+ explicit CheatsManager(Core::System& system, QWidget* parent = nullptr);
~CheatsManager();
signals:
@@ -64,6 +65,8 @@ private:
std::string m_game_tdb_id;
u16 m_revision = 0;
+ Core::System& m_system;
+
QDialogButtonBox* m_button_box;
PartiallyClosableTabWidget* m_tab_widget = nullptr;
diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp
index a76fd36b55..e70d4f64f1 100644
--- a/Source/Core/DolphinQt/MainWindow.cpp
+++ b/Source/Core/DolphinQt/MainWindow.cpp
@@ -456,7 +456,7 @@ void MainWindow::CreateComponents()
m_watch_widget = new WatchWidget(this);
m_breakpoint_widget = new BreakpointWidget(this);
m_code_widget = new CodeWidget(this);
- m_cheats_manager = new CheatsManager(this);
+ m_cheats_manager = new CheatsManager(Core::System::GetInstance(), this);
m_assembler_widget = new AssemblerWidget(this);
const auto request_watch = [this](QString name, u32 addr) {