PCSX2 / pcsx2

PCSX2 - The Playstation 2 Emulator
https://pcsx2.net
GNU General Public License v3.0
11.78k stars 1.63k forks source link

User crosshair port 2 not showing when both ports are set to GunCon 2 #11423

Open benclau opened 4 months ago

benclau commented 4 months ago

Describe the Bug

When playing lightgun games, the P2 crosshair is not showing even if a crosshair image is provided. This happens only when both ports use crosshair images. When an image is provided on 1 port (port 1 or port 2), the crosshair is displayed correctly on this port.

Reproduction Steps

1- Configure Port 1 and Port 2 as GunCon 2 2- Select an image for both ports 3- Start a lightgun game (Virtual Cop Elite edition, Vampire Night, etc) 4- Crosshair is showing up only in Port 1.

Expected Behavior

To have both crosshair displayed.

PCSX2 Revision

1.7.5912

Operating System

Windows 10 (64bit)

If Linux - Specify Distro

No response

Logs & Dumps

No response

carolis15 commented 4 months ago

I'm having the exact same problem

bslenul commented 4 months ago

When using "Relative Aiming" (for my tests I used my left analog for P1 crosshair and right analog for P2 crosshair) it kinda works, but for some reason I have to clear P2 cursor path then set it again, and only then it starts to work properly:

https://github.com/PCSX2/pcsx2/assets/33353403/e132d54e-5956-47fe-9379-66918a772b02

So baiscally what happens in the video:

  1. Only P1 crosshair shows, I move the left analog and it moves properly, nothing happens if I move right analog.
  2. I empty P2 crosshair path then re-set it.
  3. Now it works, both crosshairs appear and right analog properly moves P2 crosshair.
bslenul commented 3 months ago

I wanted to check if the paths were set correctly so I did a very simple test, in this function:

https://github.com/PCSX2/pcsx2/blob/dfb857b68f7e6cd52a55efa1f4242396a643567c/pcsx2/ImGui/ImGuiManager.cpp#L1027-L1046

which is called from https://github.com/PCSX2/pcsx2/blob/dfb857b68f7e6cd52a55efa1f4242396a643567c/pcsx2/USB/usb-lightgun/guncon2.cpp#L529-L533

BEFORE this line https://github.com/PCSX2/pcsx2/blob/dfb857b68f7e6cd52a55efa1f4242396a643567c/pcsx2/ImGui/ImGuiManager.cpp#L1029 I added logging with this: INFO_LOG("image_path port {} before: {}", index, image_path); and AFTER it I added: INFO_LOG("image_path port {} after: {}", index, image_path);.

This is the logs I get on successful attempts (both cursors appear):

[    8.0486] Opening USB...
[    8.0486] (USB) Creating a GunCon 2 in port 1
[    8.0487] image_path port 0 before: 
[    8.0488] image_path port 1 before: C:\Users\B-S\Desktop\xhair1.png
[    8.0488] (USB) Creating a GunCon 2 in port 2
[    8.0488] image_path port 0 after: 
[    8.0489] image_path port 1 after: C:\Users\B-S\Desktop\xhair1.png
[    8.0489] image_path port 0 before: 
[    8.0490] image_path port 2 before: C:\Users\B-S\Desktop\xhair2.png
[    8.0490] Opening FW...
[    8.0492] image_path port 0 after: 
[    8.0492] image_path port 2 after: C:\Users\B-S\Desktop\xhair2.png

and on failed attempts (only the 1st cursor appears):

[    3.3032] Opening USB...
[    3.3032] (USB) Creating a GunCon 2 in port 1
[    3.3033] image_path port 0 before: 
[    3.3034] image_path port 1 before: C:\Users\B-S\Desktop\xhair1.png
[    3.3034] (USB) Creating a GunCon 2 in port 2
[    3.3034] image_path port 0 after: 
[    3.3035] image_path port 1 after: C:\Users\B-S\Desktop\xhair1.png
[    3.3035] image_path port 0 before: 
[    3.3035] image_path port 2 before: C:\Users\B-S\Desktop\xhair2.png
[    3.3035] Opening FW...

These 2 lines are missing after Opening FW...:

[    8.0492] image_path port 0 after: 
[    8.0492] image_path port 2 after: C:\Users\B-S\Desktop\xhair2.png

so it looks like the lambda in that MTGS::RunOnGSThread() call is just "skipped" sometimes? Preventing 2nd cursor to appear 🤔

I suck at debugging so sorry in advance if all of this is useless...

benclau commented 2 months ago

I am not a programmer but i am interested in it and i wanted to check if a can debug this.

It appears that in [ImGuiManager.cpp] void ImGuiManager::SetSoftwareCursor(u32 index, std::string image_path, float image_scale, u32 multiply_color) { MTGS::RunOnGSThread([index, image_path = std::move(image_path), image_scale, multiply_color]() { pxAssert(index < std::size(s_software_cursors)); SoftwareCursor& sc = s_software_cursors[index]; sc.color = multiply_color | 0xFF000000; if (sc.image_path == image_path && sc.scale == image_scale) return;

    const bool is_hiding_or_showing = (image_path.empty() != sc.image_path.empty());
    sc.image_path = std::move(image_path);
    sc.scale = image_scale;
    if (MTGS::IsOpen())
         UpdateSoftwareCursorTexture(index);

    // Hide the system cursor when we activate a software cursor.
    if (is_hiding_or_showing && index == 0)
        Host::RunOnCPUThread(&InputManager::UpdateHostMouseMode);
});

} If i remove the MTGS::RunOnGSThread as shown below, void ImGuiManager::SetSoftwareCursor(u32 index, std::string image_path, float image_scale, u32 multiply_color) { // MTGS::RunOnGSThread([index, image_path = std::move(image_path), image_scale, multiply_color]() { pxAssert(index < std::size(s_software_cursors)); SoftwareCursor& sc = s_software_cursors[index]; sc.color = multiply_color | 0xFF000000; if (sc.image_path == image_path && sc.scale == image_scale) return;

    const bool is_hiding_or_showing = (image_path.empty() != sc.image_path.empty());
    sc.image_path = std::move(image_path);
    sc.scale = image_scale;
    if (MTGS::IsOpen())
         UpdateSoftwareCursorTexture(index);

    // Hide the system cursor when we activate a software cursor.
    if (is_hiding_or_showing && index == 0)
        Host::RunOnCPUThread(&InputManager::UpdateHostMouseMode);
// });

}

Everything seems to work as normal. It has something to do with running the code on the GS thread that cause this issue.

I have compiled my own code and it's working fine but i don't know if it will break something else.