Skip to content

Commit b5849a2

Browse files
committed
Pass mutex to tools window (unsafe reads, safe writes)
1 parent 32d17e1 commit b5849a2

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

Diff for: desktop-ui/desktop-ui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ auto nall::main(Arguments arguments) -> void {
156156

157157
Instances::presentation.construct();
158158
Instances::settingsWindow.construct();
159-
Instances::toolsWindow.construct();
160159
Instances::gameBrowserWindow.construct();
161160

162161
program.create();
162+
Instances::toolsWindow.construct(&program.programMutex);
163163
Application::onMain({&Program::main, &program});
164164
Application::run();
165165

Diff for: desktop-ui/tools/cheats.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ auto CheatEditor::Cheat::update(string description, string code, bool enabled) -
1616
return *this;
1717
}
1818

19-
auto CheatEditor::construct() -> void {
19+
auto CheatEditor::construct(std::recursive_mutex *programMutexIn) -> void {
20+
this->programMutex = programMutexIn;
2021
setCollapsible();
2122
setVisible(false);
2223
cheatsLabel.setText("Cheats").setFont(Font().setBold());
2324

2425
descriptionLabel.setText("Description:");
2526
codeLabel.setText("Code:");
2627
deleteButton.setText("Delete").onActivate([&] {
28+
lock_guard<recursive_mutex> lock(*programMutex);
2729
if(auto item = cheatList.selected()) {
2830
if(auto cheat = item.attribute<Cheat*>("cheat")) {
2931
if(auto c = cheats.find([cheat](auto& c) { return &c == cheat; })) {
@@ -38,6 +40,7 @@ auto CheatEditor::construct() -> void {
3840
}).setEnabled(false);
3941

4042
saveButton.setText("Save").onActivate([&] {
43+
lock_guard<recursive_mutex> lock(*programMutex);
4144
string description = descriptionEdit.text();
4245
string code = codeEdit.text();
4346

@@ -51,6 +54,7 @@ auto CheatEditor::construct() -> void {
5154
});
5255

5356
cheatList.onToggle([&](auto cell) {
57+
lock_guard<recursive_mutex> lock(*programMutex);
5458
if(auto item = cheatList.selected()) {
5559
if(auto cheat = item.attribute<Cheat*>("cheat")) {
5660
cheat->enabled = cell.checked();
@@ -59,6 +63,7 @@ auto CheatEditor::construct() -> void {
5963
});
6064

6165
cheatList.onChange([&] {
66+
lock_guard<recursive_mutex> lock(*programMutex);
6267
deleteButton.setEnabled(false);
6368
descriptionEdit.setText("");
6469
codeEdit.setText("");
@@ -74,6 +79,7 @@ auto CheatEditor::construct() -> void {
7479
}
7580

7681
auto CheatEditor::reload() -> void {
82+
lock_guard<recursive_mutex> lock(*programMutex);
7783
cheats.reset();
7884

7985
location = emulator->locate(emulator->game->location, {".cheats.bml"});
@@ -92,6 +98,7 @@ auto CheatEditor::reload() -> void {
9298
}
9399

94100
auto CheatEditor::refresh() -> void {
101+
lock_guard<recursive_mutex> lock(*programMutex);
95102
cheatList.reset();
96103
cheatList.setHeadered();
97104
cheatList.append(TableViewColumn());
@@ -111,6 +118,7 @@ auto CheatEditor::refresh() -> void {
111118
}
112119

113120
auto CheatEditor::unload() -> void {
121+
lock_guard<recursive_mutex> lock(*programMutex);
114122
bool hasCheats = cheats.size() > 0;
115123
bool isCheatLocation = location.endsWith(".cheats.bml");
116124

@@ -137,6 +145,7 @@ auto CheatEditor::unload() -> void {
137145
}
138146

139147
auto CheatEditor::find(uint address) -> maybe<u32> {
148+
lock_guard<recursive_mutex> lock(*programMutex);
140149
for(auto& cheat : cheats) {
141150
if(!cheat.enabled) continue;
142151
if(auto result = cheat.addressValuePairs.find(address)) return result();

Diff for: desktop-ui/tools/graphics.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
auto GraphicsViewer::construct() -> void {
1+
auto GraphicsViewer::construct(std::recursive_mutex *programMutexIn) -> void {
2+
this->programMutex = programMutexIn;
23
setCollapsible();
34
setVisible(false);
45

Diff for: desktop-ui/tools/memory.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
auto MemoryEditor::construct() -> void {
1+
auto MemoryEditor::construct(std::recursive_mutex *programMutexIn) -> void {
2+
this->programMutex = programMutexIn;
23
setCollapsible();
34
setVisible(false);
45

@@ -8,11 +9,13 @@ auto MemoryEditor::construct() -> void {
89
memoryEditor.setRows(24);
910

1011
exportButton.setText("Export").onActivate([&] {
12+
lock_guard<recursive_mutex> lock(*programMutex);
1113
eventExport();
1214
});
1315

1416
gotoLabel.setText("Goto:");
1517
gotoAddress.setFont(Font().setFamily(Font::Mono)).onActivate([&] {
18+
lock_guard<recursive_mutex> lock(*programMutex);
1619
auto address = gotoAddress.text().hex();
1720
memoryEditor.setAddress(address);
1821
gotoAddress.setText();
@@ -21,6 +24,7 @@ auto MemoryEditor::construct() -> void {
2124
liveOption.setText("Live");
2225

2326
refreshButton.setText("Refresh").onActivate([&] {
27+
lock_guard<recursive_mutex> lock(*programMutex);
2428
memoryEditor.update();
2529
});
2630
}
@@ -58,6 +62,7 @@ auto MemoryEditor::eventChange() -> void {
5862
return memory->read(address);
5963
});
6064
memoryEditor.onWrite([=](u32 address, u8 data) -> void {
65+
lock_guard<recursive_mutex> lock(*programMutex);
6166
return memory->write(address, data);
6267
});
6368
}
@@ -71,6 +76,7 @@ auto MemoryEditor::eventChange() -> void {
7176
}
7277

7378
auto MemoryEditor::eventExport() -> void {
79+
lock_guard<recursive_mutex> lock(*programMutex);
7480
if(auto item = memoryList.selected()) {
7581
if(auto memory = item.attribute<ares::Node::Debugger::Memory>("node")) {
7682
auto identifier = memory->name().downcase().replace(" ", "-");

Diff for: desktop-ui/tools/tools.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ StreamManager& streamManager = toolsWindow.streamManager;
1717
PropertiesViewer& propertiesViewer = toolsWindow.propertiesViewer;
1818
TraceLogger& traceLogger = toolsWindow.traceLogger;
1919

20-
ToolsWindow::ToolsWindow() {
20+
ToolsWindow::ToolsWindow(std::recursive_mutex *programMutex) {
2121

2222
panelList.append(ListViewItem().setText("Manifest").setIcon(Icon::Emblem::Binary));
2323
panelList.append(ListViewItem().setText("Cheats").setIcon(Icon::Emblem::Text));
@@ -43,9 +43,9 @@ ToolsWindow::ToolsWindow() {
4343
panelContainer.append(homePanel, Size{~0, ~0});
4444

4545
manifestViewer.construct();
46-
cheatEditor.construct();
47-
memoryEditor.construct();
48-
graphicsViewer.construct();
46+
cheatEditor.construct(programMutex);
47+
memoryEditor.construct(programMutex);
48+
graphicsViewer.construct(programMutex);
4949
streamManager.construct();
5050
propertiesViewer.construct();
5151
traceLogger.construct();

Diff for: desktop-ui/tools/tools.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ struct ManifestViewer : VerticalLayout {
1212
};
1313

1414
struct CheatEditor : VerticalLayout {
15-
auto construct() -> void;
15+
auto construct(std::recursive_mutex *programMutex) -> void;
1616
auto reload() -> void;
1717
auto unload() -> void;
1818
auto refresh() -> void;
1919
auto setVisible(bool visible = true) -> CheatEditor&;
2020

2121
auto find(u32 address) -> maybe<u32>;
22+
23+
std::recursive_mutex *programMutex;
2224

2325
Label cheatsLabel{this, Size{~0, 0}, 5};
2426
HorizontalLayout editLayout{this, Size{~0, 0}};
@@ -47,14 +49,16 @@ struct CheatEditor : VerticalLayout {
4749
};
4850

4951
struct MemoryEditor : VerticalLayout {
50-
auto construct() -> void;
52+
auto construct(std::recursive_mutex *programMutex) -> void;
5153
auto reload() -> void;
5254
auto unload() -> void;
5355
auto refresh() -> void;
5456
auto liveRefresh() -> void;
5557
auto eventChange() -> void;
5658
auto eventExport() -> void;
5759
auto setVisible(bool visible = true) -> MemoryEditor&;
60+
61+
std::recursive_mutex *programMutex;
5862

5963
Label memoryLabel{this, Size{~0, 0}, 5};
6064
ComboButton memoryList{this, Size{~0, 0}};
@@ -69,14 +73,16 @@ struct MemoryEditor : VerticalLayout {
6973
};
7074

7175
struct GraphicsViewer : VerticalLayout {
72-
auto construct() -> void;
76+
auto construct(std::recursive_mutex *programMutex) -> void;
7377
auto reload() -> void;
7478
auto unload() -> void;
7579
auto refresh() -> void;
7680
auto liveRefresh() -> void;
7781
auto eventChange() -> void;
7882
auto eventExport() -> void;
7983
auto setVisible(bool visible = true) -> GraphicsViewer&;
84+
85+
std::recursive_mutex *programMutex;
8086

8187
Label graphicsLabel{this, Size{~0, 0}, 5};
8288
ComboButton graphicsList{this, Size{~0, 0}};
@@ -128,7 +134,7 @@ struct TraceLogger : VerticalLayout {
128134
};
129135

130136
struct ToolsWindow : Window {
131-
ToolsWindow();
137+
ToolsWindow(std::recursive_mutex *programMutex);
132138
auto show(const string& panel) -> void;
133139
auto eventChange() -> void;
134140

0 commit comments

Comments
 (0)