grumpycoders / pcsx-redux

The PCSX-Redux project is a collection of tools, research, hardware design, and libraries aiming at development and reverse engineering on the PlayStation 1. The core product itself, PCSX-Redux, is yet another fork of the Playstation emulator, PCSX.
https://pcsx-redux.consoledev.net
GNU General Public License v2.0
658 stars 108 forks source link

SIGFPE running PCSX-Redux AppImage #714

Open skierpage opened 2 years ago

skierpage commented 2 years ago

Describe the bug

I downloaded the AppImage and tried to run it on Fedora, running KDE on Wayland. I had some problems.

error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such file or directory

This seems a known issue, e.g. this bug, so

sudo dnf --setopt=install_weak_deps=False install libnsl

Retry, now a window briefly appears but then

zsh: floating point exception (core dumped)  ./PCSX-Redux-HEAD-x86_64.AppImage

but no core file appears and Fedora's `abrt bug reporter isn't triggered.

Running gdb after --app-image-mount, I get

#0  0x0000000000497e48 in ?? ()
#1  0x0000000000475590 in ?? ()
#2  0x00000000004960cb in ?? ()
#3  0x00000000005a725b in ?? ()
#4  0x000000000058e96b in ?? ()
#5  0x0000000000608d45 in ?? ()
#6  0x000000000060f6ba in ?? ()
#7  0x00007ffff5bc8560 in __libc_start_call_main (main=main@entry=0x60f680, argc=argc@entry=1, 
    argv=argv@entry=0x7fffffffcdc8) at ../sysdeps/nptl/libc_start_call_main.h:58
#8  0x00007ffff5bc860c in __libc_start_main_impl (main=0x60f680, argc=1, argv=0x7fffffffcdc8, init=<optimized out>, 
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffcdb8) at ../csu/libc-start.c:409
#9  0x000000000044a01e in ?? ()

While trying to debug this further I got a similar warning loading shared library libglfw.so.3, so

% sudo dnf --setopt=install_weak_deps=False install glfw

but that didn't help.

Expected behavior

Works or does not crash.

Steps to reproduce the bug

  1. Download PCSX-Redux-43164118-linux-x86_64.zip
  2. unzip to ~/programs
  3. cd ~/programs
  4. ./PCSX-Redux-HEAD-x86_64.AppImage (crashes)
  5. ./PCSX-Redux-HEAD-x86_64.AppImage --appimage-mount
  6. cd /tmp
  7. gdb /tmp/.mount_PCSX-RB4tEE1/AppRun

Operating System

Fedora 35

CPU model

4 × Intel® Core™ i5-6300U CPU @ 2.40GHz

GPU model

Mesa Intel® HD Graphics 520

BIOS version

haven't got that far

CPU emulation mode

Interpreter

Additional information

I never get to the menu bar. I tried both --interpreter and --dynarec command-line options and both crash with floating point exception.

nicolasnoble commented 2 years ago

Huh, interesting. I'll try to set up a fedora vm somewhere to reproduce this one.

nicolasnoble commented 2 years ago

Try adding -stdout to potentially get more information.

skierpage commented 2 years ago

Thanks for responding :+1:

Try adding -stdout to potentially get more information.

(gdb) run -stdout

didn't output much more information:

...
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
...
Thread 1 "pcsx-redux" received signal SIGFPE, Arithmetic exception.
<same stack trace>

gdb doesn't know what's at the stack addresses in the backtrace, I'm not sure what symbols libraries to install with debuginfo-install to help source-level debugging.

nicolasnoble commented 2 years ago

What's your GPU drivers btw? This really just means there's a division by zero somewhere, which is likely one of the functions computing window sizes or something.

skierpage commented 2 years ago

What's your GPU drivers btw? This really just means there's a division by zero somewhere, which is likely one of the functions computing window sizes or something.

No idea about my GPU drivers; whatever Fedora 35 provides/uses when running Wayland. lsmod | rg drm shows drm_kms_helper,i915.

I wonder if PCSX-Redux is using X11 or Wayland. If I run /tmp/.mount_PCSX-blahblah/AppRun or /tmp/.mount_PCSX-blahblah/usr/bin/pcsx-redux under gdb, I see a reasonably-sized "PCSX-Redux" window appears with nice icon and black contents, and xlsclients doesn't list any X11 clients, but maybe it's dying early on. glfw (remember as mentioned above I had to install Fedora's library glfw-3.3.4-3.fc35, the AppImage couldn't find it) seems to support running as X11 or Wayland at runtime but I couldn't figure out how to control this.

nicolasnoble commented 2 years ago

Oh, I missed the part where you're relying on the host's glfw. This may be bad. Huh. Why didn't AppImage pick up the fact it requires glfw, and how is this working elsewhere...

skierpage commented 2 years ago

I wonder if PCSX-Redux is using X11 or Wayland.

FYI I convinced PCSX_Redux to run on a nested X11 kwin, and it crashed with the same backtrace.

weimzh commented 2 years ago

this is what I got under fedora 35, not sure if it's related to pirewire:

0x00000000006894d7 in ma_device_init__pulse (pDevice=0x7fffec055508, pConfig=0x7fffec055410, pDescriptorPlayback=0x7fffffffbf20, pDescriptorCapture=0x7fffffffbf70) at third_party/miniaudio/miniaudio.h:23468
23468           pDescriptorPlayback->periodSizeInFrames = attr.maxlength / ma_get_bytes_per_frame(pDescriptorPlayback->format, pDescriptorPlayback->channels) / pDescriptorPlayback->periodCount;

(gdb) bt
#0  0x00000000006894d7 in ma_device_init__pulse(ma_device*, ma_device_config const*, ma_device_descriptor*, ma_device_descriptor*) (pDevice=0x7fffec055508, pConfig=0x7fffec055410, pDescriptorPlayback=0x7fffffffbf20, pDescriptorCapture=0x7fffffffbf70)
    at third_party/miniaudio/miniaudio.h:23468
#1  0x000000000068a156 in ma_device_init(ma_context*, ma_device_config const*, ma_device*) (pContext=pContext@entry=0x7fffec054fa0, pConfig=pConfig@entry=0x7fffec055410, pDevice=pDevice@entry=0x7fffec055508) at third_party/miniaudio/miniaudio.h:33757
#2  0x000000000068f824 in PCSX::SPU::MiniAudio::init() (this=0x7fffec054f98) at src/spu/miniaudio.cc:147
#3  0x00000000005bc93b in std::function<void (PCSX::Events::SettingsLoaded const&)>::operator()(PCSX::Events::SettingsLoaded const&) const (__args#0=..., this=<optimized out>) at /usr/include/c++/11/bits/std_function.h:590
#4  PCSX::EventBus::EventBus::signal<PCSX::Events::SettingsLoaded>(PCSX::Events::SettingsLoaded const&) (event=..., this=<optimized out>) at src/support/eventbus.h:83
#5  PCSX::GUI::init() (this=this@entry=0x54a4f00) at src/gui/gui.cc:373
#6  0x000000000064ec69 in pcsxMain(int, char**) (argc=argc@entry=1, argv=argv@entry=0x7fffffffdbf8) at src/main/main.cc:174
#7  0x000000000044600b in loopMain (argv=0x7fffffffdbf8, argc=1) at src/main/mainthunk.cc:33
#8  main(int, char**) (argc=1, argv=0x7fffffffdbf8) at src/main/mainthunk.cc:124

(gdb) p  pDescriptorPlayback->periodCount
$3 = 0

// pDescriptorPlayback->periodCount        = attr.maxlength / attr.tlength;

(gdb) p attr.maxlength
$4 = 512
(gdb) p attr.tlength
$5 = 6144
nicolasnoble commented 2 years ago

Oh! This may be a bug in miniaudio! Very nice findings.

skierpage commented 2 years ago

this is what I got under fedora 35, not sure if it's related to pirewire:

You're doing better than me :wink: ! Did you have to install libnsl and glfw as I had to? Are you running in a Wayland window manager?

How did you get the nice symbols in gdb, did you allow DEBUG_INFOD_URLS or just manually dnf debuginfo-install everything, or did you compile the AppImage yourself?

weimzh commented 2 years ago

I probably already have all of the libraries installed, and I cannot use wayland due to the nvidia proprietary driver.

use: make BUILD=Debug to generate a debug build. The provided binaries in appimage is stripped and do not contain the debug symbols.

nicolasnoble commented 2 years ago

With #726 merged in, can you try calling with -safe? This will now set the SPU backend driver to Null. Use Configuration->SPU to select a new backend. It may be that the default backend that miniaudio is selecting breaks for you before anything happens.

If this helps, it may be worth updating to the latest version of miniaudio, and if it still breaks, report a bug to miniaudio.

weimzh commented 2 years ago

use -safe and then set the backend driver to alsa works well. probably it's due to fedora replaced pulseaudio with pirewire but I have not checked it yet

updating to the latest version of miniaudio also fixes this particular issue, but it still crashes when launching any games. This assertion fails:

52300: MA_ASSERT(pConverter->resampler.channels < pConverter->channelConverter.channelsIn);

nicolasnoble commented 2 years ago

Brilliant. I'll make an update of the miniaudio submodule. Do you think you could file an issue on the miniaudio repository, since you have the reproduction environment?

https://github.com/mackron/miniaudio/issues/new/choose