pierr3 / VectorAudio

An Audio-For-VATSIM ATC Client for macOS, Linux and Windows
GNU General Public License v3.0
48 stars 11 forks source link

Ubuntu 20.04: no sound API; segfault when trying to select input/output device #10

Closed pole95 closed 1 year ago

pole95 commented 2 years ago

When trying to configure VectorAudio on Ubuntu 20.04, I am not able to select a sound API in the settings. Logically, trying to set an input/output device then fails, with VectorAudio crashing with a segfault.

In order to test if the problem was on my side, I wrote a quick test program which queries portaudio using the same calls as VectorAudio/afv-native:

#include<portaudio.h>
#include<iostream>

int main()
{
    Pa_Initialize();

    int hostapis = Pa_GetHostApiCount();
    std::cout << hostapis << std::endl;

    auto apiCount = Pa_GetHostApiCount();
    for (unsigned i = 0; i < apiCount; i++) {
        auto info = Pa_GetHostApiInfo(i);
        if (info != nullptr) {
            std::cout << i << ": "<< info->name << std::endl;
        }
        for(unsigned j = 0; j < info->deviceCount; j++){
            auto devId = Pa_HostApiDeviceIndexToDeviceIndex(i,j);
            if(devId < 0)
                continue;
            const auto *devInfo = Pa_GetDeviceInfo(devId);
            std::cout << "\t" << j << ": " << devInfo->name << std::endl;
        }
    }

    Pa_Terminate();
}

This gives me the expected output:

2
0: ALSA
    0: USB Device 0x46d:0x825: Audio (hw:0,0)
    1: Steinberg UR22: USB Audio (hw:1,0)
    2: HDA Intel PCH: ALC887-VD Analog (hw:2,0)
    3: HDA Intel PCH: ALC887-VD Alt Analog (hw:2,2)
    4: HDA NVidia: HDMI 0 (hw:3,3)
    5: HDA NVidia: HDMI 1 (hw:3,7)
    6: HDA NVidia: HDMI 2 (hw:3,8)
    7: HDA NVidia: HDMI 3 (hw:3,9)
    8: HDA NVidia: HDMI 4 (hw:3,10)
    9: HDA NVidia: HDMI 5 (hw:3,11)
    10: sysdefault
    11: spdif
    12: samplerate
    13: speexrate
    14: pulse
    15: upmix
    16: vdownmix
    17: default
1: OSS
jamieernest commented 2 years ago

+1, am on Pop! OS 21.10

pierr3 commented 2 years ago

Permissions issue with the binary perhaps? If you compile it yourself, do you face the same issue?

jamieernest commented 2 years ago

Nope, binary refuses to start (missing library, I add library the icon png has a wrong name I change the png name it starts and crashes immediately with Segmentation fault), build crashes when I try to choose an audio device (Segmentation Error)

Not sure if this matters (still new to linux cos I was only using it on my spare machine and now on my main aswell because I just can't stand Windows) I've tried on both Pop! OS 21.10 GNOME and KDE

jonaseberle commented 2 years ago

I am on Linux, too (Manjaro/arch). I keep these audio settings at default and do the routing in pulseaudio (since all, including my bluetooth devices are managed by it) and that works fine.

image

I just realize that stdout is spammed with thousands of messages like this:

FillInDevInfo: Adding device front: 7
FillInDevInfo: Filling device info for: rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
OpenPcm: Opened device 'rear' ptr[(nil)] - result: [-2:No such file or directory]
FillInDevInfo: Skipped device: rear, all channels == 0
FillInDevInfo: Filling device info for: center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
OpenPcm: Opened device 'center_lfe' ptr[(nil)] - result: [-2:No such file or directory]
FillInDevInfo: Skipped device: center_lfe, all channels == 0
FillInDevInfo: Filling device info for: side
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
OpenPcm: Opened device 'side' ptr[(nil)] - result: [-2:No such file or directory]
FillInDevInfo: Skipped device: side, all channels == 0
FillInDevInfo: Filling device info for: surround21
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
OpenPcm: Opened device 'surround21' ptr[(nil)] - result: [-22:Invalid argument]
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
OpenPcm: Opened device 'surround21' ptr[(nil)] - result: [-22:Invalid argument]
FillInDevInfo: Skipped device: surround21, all channels == 0
FillInDevInfo: Filling device info for: surround40
GropeDevice: collecting info ..
...

... and CPU is at 100% while any of the selectboxes is opened.

pole95 commented 2 years ago

I can't use the precompiled binary, it complains about not finding libafv.so.

I checked running the binary with sudo and its the same error. The test code I posted in the first comment also gives me all my devices when its run as a regular user.

If I keep the audio settings as default the program segfaults when trying to connect, presumably while trying to open a non-existent input/output device. IMO this is expected.

@jonaseberle the stdout spamming seems to come from portaudio and the ALSA defaults, I get that as well when I open, e.g. the xPilot AppImage through the terminal.

jonaseberle commented 2 years ago

I've always compiled myself but just tried the asset from the latest release.

$ ldd vector_audio 
        linux-vdso.so.1 (0x00007fff5f591000)
        libGL.so.1 => /usr/lib/libGL.so.1 (0x00007f1a5f486000)
        libafv.so => not found
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1a5f481000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f1a5f47c000)
        libudev.so.1 => /usr/lib/libudev.so.1 (0x00007f1a5f450000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f1a5f30e000)
        libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0x00007f1a5f2ff000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f1a5f0d9000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f1a5eff1000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f1a5efd6000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f1a5edcc000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f1a5fb32000)
        libGLdispatch.so.0 => /usr/lib/libGLdispatch.so.0 (0x00007f1a5ed14000)
        libGLX.so.0 => /usr/lib/libGLX.so.0 (0x00007f1a5ecdf000)
        libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f1a5ecb5000)
        libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f1a5eca0000)
        libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007f1a5ec93000)
        libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f1a5ec8e000)
        libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f1a5ec84000)

$ ./vector_audio 
./vector_audio: error while loading shared libraries: libafv.so: cannot open shared object file: No such file or directory

$ LD_LIBRARY_PATH=./ ./vector_audio 
Failed to load image "/tmp/VectorAudio_Linux/VectorAudio_Linux/vector_audioicon_mac.png". Reason: Unable to open file
Segmentation fault (core dumped)
jonaseberle commented 2 years ago

If you want I can look into the core dump where it segfaults. (That image it is trying to load should be icon_mac.png)

pole95 commented 2 years ago

Well, after an apt upgrade and a complete recompilation it now suddenly works...

No significant upgrades that I can see in the apt history, except for a new kernel. Weird...

pierr3 commented 2 years ago

I genuinely don't know why this is happening, I think overall we should move to miniaudio to support more audio APIs on Linux, Justin is working on that. if anyone has any pointers let me know.

pierr3 commented 2 years ago

I've always compiled myself but just tried the asset from the latest release.

$ ldd vector_audio 
        linux-vdso.so.1 (0x00007fff5f591000)
        libGL.so.1 => /usr/lib/libGL.so.1 (0x00007f1a5f486000)
        libafv.so => not found
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1a5f481000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f1a5f47c000)
        libudev.so.1 => /usr/lib/libudev.so.1 (0x00007f1a5f450000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f1a5f30e000)
        libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0x00007f1a5f2ff000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f1a5f0d9000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f1a5eff1000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f1a5efd6000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f1a5edcc000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f1a5fb32000)
        libGLdispatch.so.0 => /usr/lib/libGLdispatch.so.0 (0x00007f1a5ed14000)
        libGLX.so.0 => /usr/lib/libGLX.so.0 (0x00007f1a5ecdf000)
        libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f1a5ecb5000)
        libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f1a5eca0000)
        libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007f1a5ec93000)
        libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f1a5ec8e000)
        libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f1a5ec84000)

$ ./vector_audio 
./vector_audio: error while loading shared libraries: libafv.so: cannot open shared object file: No such file or directory

$ LD_LIBRARY_PATH=./ ./vector_audio 
Failed to load image "/tmp/VectorAudio_Linux/VectorAudio_Linux/vector_audioicon_mac.png". Reason: Unable to open file
Segmentation fault (core dumped)

Thanks for reporting this, need to fix the linking and the resource path function!

pierr3 commented 2 years ago

Does the segfault wrt to the Icon file still occur? Or has that been fixed?

jonaseberle commented 2 years ago

The downloaded release does not segfault due to the icon any more. But it still does not discover libafv.so automatically and it segfaults at another point for me:

$ ./vector_audio 
./vector_audio: error while loading shared libraries: libafv.so: cannot open shared object file: No such file or directory
$ LD_LIBRARY_PATH=./ ./vector_audio 
Segmentation fault (core dumped)

It briefly creates the main window, then crashes.

(gdb) bt
#0  0x000055c01c57325d in httplib::Request::Request(httplib::Request const&) ()
#1  0x000055c01c5afc15 in httplib::ClientImpl::handle_request(httplib::Stream&, httplib::Request&, httplib::Response&, bool, httplib::Error&) ()
#2  0x000055c01c53e09c in httplib::SSLClient::process_socket(httplib::ClientImpl::Socket const&, std::function<bool (httplib::Stream&)>) ()
#3  0x000055c01c5ac788 in httplib::ClientImpl::send(httplib::Request&, httplib::Response&, httplib::Error&) ()
#4  0x000055c01c6379aa in afv_unix::updater::updater() ()
#5  0x000055c01c537c6e in main ()
pierr3 commented 2 years ago

Can you try running it with the below command? I suspect forcing LD_LIBRARY_PATH to only the local directory causes the openssl import to fail.

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./ ./vector_audio

jonaseberle commented 2 years ago

Thanks for the hint. On my system $LD_LIBRARY_PATH is empty, though. So this has the same outcome.

CPU-Blanc commented 1 year ago

Having the same issues here on EndeavourOS 6.0.9-arch1-1. I have to compile from source and the audio API is not selectable. The release version doesn't find libafv.so. As per above, my $LD_LIBRARY_PATH is also empty

pierr3 commented 1 year ago

This should have been fixed the latest pre-release, I forced the rpath to include the lib in the executable folder. On another note, if anyone wants to help create an AppImage release, feel free to do a PR! I'll also soon issue a release

jonaseberle commented 1 year ago

I've had problems with packaging C++ apps and progress on that stalled from my side :( . For the next months I probably can't make the time and won't work on it.