fgsfdsfgs / perfect_dark

work in progress port of n64decomp/perfect_dark to modern platforms
MIT License
1.21k stars 75 forks source link

Intermittent hang when using aim mode #219

Open SilentException opened 11 months ago

SilentException commented 11 months ago

Playing on Steam Deck (Linux build), Xbox controls + trackpad as mouse. In Villa mission I've noticed that using aim mode sometimes hangs the game and CPU goes to 100. Deadlock? I have to kill the game manually. I also experienced this once in Carrington weapon training room but I didn't give it much attention at the time. Let me know if there are any logs I could attach, haven't found any.

cylonicboom commented 11 months ago

Are you mixing mouse and joystick aim inputs? Is the joystick as a joystick mouse?

SilentException commented 11 months ago

Are you mixing mouse and joystick aim inputs? Is the joystick as a joystick mouse?

Yup, that's why I wrote using trackpad 'as mouse'. It is really good and precise way to play on SD especially now with addition of analog movement.

fgsfdsfgs commented 11 months ago

If the game doesn't crash, there are no logs. The only thing you could do is attach GDB to it and see where it's locked up.

SilentException commented 11 months ago

I went through gdb and it seems to be stuck in a loop here https://github.com/fgsfdsfgs/perfect_dark/blob/479c0335f3dbe021f84adbc88e858de604de36cf/src/lib/naudio/n_sndplayer.c#L95 Call to '''n_alEvtqNextEvent''' returns 0 and the while continues in circles. The return comes from here: https://github.com/fgsfdsfgs/perfect_dark/blob/479c0335f3dbe021f84adbc88e858de604de36cf/src/lib/naudio/n_event.c#L42

...with interesting comment above.

However, I'm not sure if this is the main reason process hangs or only consequence after some other issue.

Edit, gdb thread info:

(gdb) info threads
  Id   Target Id                                    Frame
* 1    Thread 0xf6bfa740 (LWP 73006) "pd"           0x5675949d in _n_sndpVoiceHandler (node=0x568e2b80 <var8009c2d0>) at src/lib/naudio/n_sndplayer.c:95
  2    Thread 0xea8a1b40 (LWP 73037) "pd:cs0"       0xf7f71549 in __kernel_vsyscall ()
  3    Thread 0xe9dbeb40 (LWP 73038) "pd:disk$0"    0xf7f71549 in __kernel_vsyscall ()
  4    Thread 0xe93bdb40 (LWP 73039) "pd:sh0"       0xf7f71549 in __kernel_vsyscall ()
  5    Thread 0xe8bbcb40 (LWP 73040) "pd:shlo0"     0xf7f71549 in __kernel_vsyscall ()
  6    Thread 0xe7bffb40 (LWP 73042) "pd:gdrv0"     0xf7f71549 in __kernel_vsyscall ()
  7    Thread 0xe95bdb40 (LWP 73043) "PulseHotplug" 0xf7f71549 in __kernel_vsyscall ()
  8    Thread 0xea06fb40 (LWP 73044) "SDLAudioP2"   0xf7f71549 in __kernel_vsyscall ()
  9    Thread 0xcb9feb40 (LWP 73046) "pd:sh1"       0xf7f71549 in __kernel_vsyscall ()
  10   Thread 0xca9ffb40 (LWP 73054) "pd:sh2"       0xf7f71549 in __kernel_vsyscall ()
fgsfdsfgs commented 11 months ago

That's completely unrelated to the aim mode and very strange if it does indeed get locked up there. I've seen this happen some time ago, but I don't recall if I did anything to fix it. Is this on PAL by any chance?

SilentException commented 11 months ago

Unrelated sure, but it always gets locked after releasing aim mode. Not always as it happens every time I use aim mode but when it happens it is after releasing left trigger. I'm using NTSC ROM (e03b088b6ac9e0080440efed07c1e40f).

Zandengoff commented 11 months ago

Wanted to chime in to say that I have the same issue. US 1.1V rom (e03b088b6ac9e0080440efed07c1e40f), Linux build, Steam Deck. Getting hard locks when aiming in Villa. Currently using the Windows version via Proton as a work around.

fgsfdsfgs commented 11 months ago

If any of you is able to build the game locally, can you try this patch? It can be applied using git apply snd-evq.patch in the repo folder. snd-evq.patch

SilentException commented 11 months ago

If any of you is able to build the game locally, can you try this patch?

Sure. I submitted PR week ago so I do have build env set up :) I actually already increased maxEvents few days back and built but haven't played much since. But I didn't increase heaplen as you did. Will be playing over the weekend. Thanks.

Zandengoff commented 11 months ago

Don't have a build environment setup atm, but if anyone provides a modified build I would be happy to try it out.

SilentException commented 11 months ago

The changes do not help, still locks up unfortunately. I've been trying few other changes in code but without success. Noticed that it is possible to "feel" when it will lock at least when using automatic weapons. While shooting, the audio will skip few bullet shot sounds and when that happens with aim mode open you're done. But not sure what triggers it, it happens randomly as far as I can tell :(

@Zandengoff do you play with gyro and/or trackpads?

fgsfdsfgs commented 11 months ago

Wonder why the fuck this only happens on some configurations. I know there are people that played through the entire game on a Steam Deck and didn't have this issue.

Zandengoff commented 11 months ago

I was using a combination of mouse control and joypad. However, I just launched the Linux build and started everything up with a standard all joystick config and it froze about 1 minute into Villa. I noticed the performance monitor (not the steam interface, just the performance monitor) was frozen so I dropped down to desktop mode to see if it made any difference. About 30 seconds in to Villa PD froze and the OS let me know it had gone unresponsive. So no change there. I thought that I would then disable steam input to see if that was causing some problem, connected an external Xbox controller and disabled steam input and it froze shortly into Villa. I think whatever is going on here is unrelated to gyro, trackpads, or mouse as that is direct communication to the Xbox controller without steam inputs involvement and it seemed to make no difference.

Edit: Wanted to also note that I am already on level 5 on the Windows build, so this is Linux build specific in some way. I am using the Steam Linux Runtime to fulfill the external library requirements, maybe there is something there that can be looked at?

SilentException commented 11 months ago

I was going to try joystick only control scheme as well but now that you tested it there is no point.

I did try different libraries too. Steam lets you only use v1 scout runtime. But check this out... Open Properties for the game in Steam and in Shortcut tab, you probably have TARGET set as full path to pd executable. In my case it is "/home/deck/Games/PerfectDarkPC/pd". Leave that as is. START IN should be directory the pd executable is located in. In my case that is /home/deck/Games/PerfectDarkPC/. LAUNCH OPTIONS are probably empty but type this in: /home/deck/.steam/steam/steamapps/common/SteamLinuxRuntime_sniper/run %command%. In Compatibility tab to not force any compatibility tool anymore. This will make the game run under newest sniper Steam runtime (which you need to have installed). I have been playing Vila for almost an hour and haven't experienced any lockups.

Zandengoff commented 11 months ago

I was going to try joystick only control scheme as well but now that you tested it there is no point.

I did try different libraries too. Steam lets you only use v1 scout runtime. But check this out... Open Properties for the game in Steam and in Shortcut tab, you probably have TARGET set as full path to pd executable. In my case it is "/home/deck/Games/PerfectDarkPC/pd". Leave that as is. START IN should be directory the pd executable is located in. In my case that is /home/deck/Games/PerfectDarkPC/. LAUNCH OPTIONS are probably empty but type this in: /home/deck/.steam/steam/steamapps/common/SteamLinuxRuntime_sniper/run %command%. In Compatibility tab to not force any compatibility tool anymore. This will make the game run under newest sniper Steam runtime (which you need to have installed). I have been playing Vila for almost an hour and haven't experienced any lockups.

Tried this and it fixed it, finished Villa no problem. Like many projects in Linux, the issue seems to be in the library somehow. Now if only to determine which library and why.

fgsfdsfgs commented 11 months ago

Even if this is fixed by swapping to a different library version, this situation should still be accounted for in the port. The problem is I don't know how because I don't know what the exact problem is. Maybe it returns the wrong queued samples value, maybe the audio sink doesn't drain fast enough.

SilentException commented 11 months ago

Sure, well I'm trying to narrow it down...

The differences in SDL2 libraries in scout and sniper Linux runtime is: libSDL2-2.0.so.0.2800.4 = libSDL2-2.0.so.0.2800.4 libSDL2_image-2.0.so.0.600.0 < libSDL2_image-2.0.so.0.600.3 libSDL2_mixer-2.0.so.0.600.1 < libSDL2_mixer-2.0.so.0.600.2 libSDL2_net-2.0.so.0.0.1 = libSDL2_net-2.0.so.0.0.1 libSDL2_ttf-2.0.so.0.2000.0 < libSDL2_ttf-2.0.so.0.2000.1

fgsfdsfgs commented 11 months ago

Out of those libraries only libSDL2 is used in the port. Must be something else. Maybe libpulse or whatever it picks for the audio backend.

SilentException commented 11 months ago

I went as far as copying the steam-runtime to my WSL Ubuntu, removing system libpulse and libsdl2 installations and then running the game through steam-runtime. I verified with lsof that libs were loaded from steam-runtime but couldn't reproduce the error. This was with keyboard only, mouse for some reason is not working properly when running inside WSL window.

cpelley commented 10 months ago

I'm experiencing frequent crashes now too. Does seem to relate to the aim. I've tried playing not using aim and it doesn't crash. When using aim or a little after it, it can crash (not on every single aim for me). I've completed the game and didn't have frequent crashes (occasional maybe) at the time so this issue was introduced by something/somewhere somehow.

cpelley commented 10 months ago

I was going to try joystick only control scheme as well but now that you tested it there is no point.

I did try different libraries too. Steam lets you only use v1 scout runtime. But check this out... Open Properties for the game in Steam and in Shortcut tab, you probably have TARGET set as full path to pd executable. In my case it is "/home/deck/Games/PerfectDarkPC/pd". Leave that as is. START IN should be directory the pd executable is located in. In my case that is /home/deck/Games/PerfectDarkPC/. LAUNCH OPTIONS are probably empty but type this in: /home/deck/.steam/steam/steamapps/common/SteamLinuxRuntime_sniper/run %command%. In Compatibility tab to not force any compatibility tool anymore. This will make the game run under newest sniper Steam runtime (which you need to have installed). I have been playing Vila for almost an hour and haven't experienced any lockups.

This worked for me too. That is, using the 'sniper' Linux runtime. Thanks for sharing.