Skip to content

Commit b9b0298

Browse files
committed
USB: Fix MTGS thread undoing crosshairs
TheLastRar: ' This issue of the missing P2 cursor seems to be caused because the GS (and thus MTGS) gets reset shortly after USBopen, causing the command to get dropped. Putting MTGS::WaitGS() at the end of this function (after the closing bracket for MTGS::RunOnGSThread()) seems enough to fix this.' Didn't see where it lost the textures before but I did identify it was happening on the MTGS thread somehow. If you uncommented it, it did work but then you get issues with OpenGL renderer.
1 parent 63ef491 commit b9b0298

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pcsx2/ImGui/ImGuiManager.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ void ImGuiManager::SetSoftwareCursor(u32 index, std::string image_path, float im
11051105
// but may cause side effects like Player 2's crosshair overlaying everything in some games (e.g., Time Crisis 2/3).
11061106
// Haven't really tested other games and also had issues even with showing inputs on my end in the OSD lower left section - RedDevilus
11071107
// This is a temporary workaround until a proper fix is implemented but it shouldn't break anything in-game (hopefully).
1108-
// MTGS::RunOnGSThread([index, image_path = std::move(image_path), image_scale, multiply_color]() {
1108+
// Update: MTGS::WaitGS(); is needed outside the function and this seems more appropiate fix and doesn't seem to break anything.
1109+
MTGS::RunOnGSThread([index, image_path = std::move(image_path), image_scale, multiply_color]() {
11091110

11101111
// Ensure the provided index is within the valid range of the software cursors array
11111112
pxAssert(index < std::size(s_software_cursors));
@@ -1153,17 +1154,23 @@ void ImGuiManager::SetSoftwareCursor(u32 index, std::string image_path, float im
11531154
sc.pos = InputManager::GetPointerAbsolutePosition(index);
11541155

11551156
// If the multi-threaded GS thread is open, update the cursor's texture to reflect the new image (example is a crosshair.png) or scale (size)
1156-
// This is necessary for rendering the crosshair correctly
1157+
// This is necessary for rendering the crosshair correctly.
1158+
// Also, need to make it run on the GSthread to ensure thread safety or OpenGL renderer will have race conditions due to not creating texture without a valid accompanying context.
11571159
if (MTGS::IsOpen())
1158-
UpdateSoftwareCursorTexture(index);
1160+
{
1161+
MTGS::RunOnGSThread([index]() {
1162+
UpdateSoftwareCursorTexture(index);
1163+
});
1164+
}
11591165

11601166
// If showing or hiding the cursor for Player 1 (index 0), update the host mouse mode
11611167
// This synchronizes the system cursor visibility with the software cursor
11621168
// Basically hides the system cursor when we activate a software cursor.
11631169
if (is_hiding_or_showing && index == 0)
11641170
Host::RunOnCPUThread(&InputManager::UpdateHostMouseMode);
11651171

1166-
// }); // Corresponding closing bracket for MTGS::RunOnGSThread on top of this function which commented out but is here in case we need to bring it back
1172+
});
1173+
MTGS::WaitGS(); // This issue of the missing P2 cursor seems to be caused because the GS (and thus MTGS) gets reset shortly after USBopen, causing the command to get dropped. Putting MTGS::WaitGS() at the end of this function (after the closing bracket for MTGS::RunOnGSThread()) seems enough to fix this. See https://github.com/PCSX2/pcsx2/pull/12697
11671174
}
11681175

11691176
bool ImGuiManager::HasSoftwareCursor(u32 index)

0 commit comments

Comments
 (0)