Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[games] Fix crash in PCSX ReARMed with BIOS #14924
Moves Streams().Initialize() back to InitializeGameplay() to solve the crash in PCSX ReARMed libretro core when run with BIOS. This is partial revert of commit 2bbd26f.
Motivation and Context
The issue was introduced as part of the PR #14146.
It is discussed here:
This needs more testing and approval from @garbear.
How Has This Been Tested?
LibreELEC on Amlogic MX2. So far 2 days without crash.
Screenshots (if appropriate):
Types of change
Thanks for your patience. I think I found the root cause. PCSX enables hardware rendering during retro_init, which causes game.libretro to immediately open a stream: https://github.com/kodi-game/game.libretro/blob/master/src/video/VideoStream.cpp#L71
By not initializing Streams, we prevent a hardware stream from opening, so PCSX probably falls back into SW mode, which prevents crashing but has a performance hit. So this solution is not optimal.
Instead, when hardware framebuffer rendering is enabled, we should defer stream open until after the game is loaded. game.libretro can set a flag and open the stream after game load. Does that make sense?
How is this being affected by the presence of BIOS? It only crashes when there is a BIOS installed in the system folder.
Is there a way how to check if it is using software or hardware framebuffer? I'm testing this on Amlogic MX2 (old 32-bit dual core ARM) and I don't see any performance drop. More demanding titles are not running at full speed (e.g. NHL 99, Tekken 3, ...) but there is no visible difference between patched and not patched version.
Can you step through PCSX in a debugger? This is how I catch bugs in libretro cores.
This is something that should be logged. Can you add a log line for this? That would at least rule out my theory.
If the crash is occurring in PCSX, not Kodi, it's because PCSX doesn't handle the order of libretro calls correctly. I've encountered several cores that make assumptions not present in the libretro API. The ideal solution would be to fix PCSX. The next best step would be to change game.libretro to guard against PCSX's bug (which is what I normally do). IMO modifying Kodi to work around a libretro core bug is the wrong approach.
I've identified a race condition that this PR could introduce. Streams must be initialized before load game takes place, because a core could deliver its first frame from inside load game (or spawn a thread from load game that races streams initialization). Load game shouldn't be called from Kodi with uninitialized streams.
What if we modify game.libretro to not open streams until load game is entered?
Long story short... I've added more logs and it seems that CVideoStream::EnableHardwareRendering is not being called at all in my case, sorry.
There are only "CVideoStream::GetSwFramebuffer" calls in both logs, no "CVideoStream::GetHwFramebuffer" or "Enabling hardware rendering".
P.S. I've just noticed this part in the log which is there every time it crashes:
It looks like the problem is in the initialization of audio stream not video.
Anything new on this? I'm using my custom builds with this PR included for about two months now and playing NES, SNES, Genesis and PSX without a single crash so I've almost forgotten that it is not solved upstream. Today I've installed the official LibreELEC build on a new Rockchip device and again it crashes when playing with PCSX.