WarmUpTill / SceneSwitcher

An automation tool for OBS Studio
https://obsproject.com/forum/resources/automatic-scene-switching.395/
GNU General Public License v2.0
970 stars 76 forks source link

Segfault when selecting audio source #108

Closed Lytigas closed 3 years ago

Lytigas commented 3 years ago

Just installed this plugin on Ubuntu 18.04. It's possible I messed up the install, but the windows seem to show up OK.

Reproduction (for me): Install 1.8.3 official build. Tools -> Advanced Scene Switcher -> Audio -> + -> Select any item in the dropdown This causes a segfault.

Logs:

$ obs --version
OBS Studio - 26.1.1 (linux)
$ obs
Gtk-Message: 22:48:41.899: Failed to load module "appmenu-gtk-module"
Attempted path: share/obs/obs-studio/locale/en-US.ini
Attempted path: /usr/share/obs/obs-studio/locale/en-US.ini
Attempted path: share/obs/obs-studio/locale.ini
Attempted path: /usr/share/obs/obs-studio/locale.ini
Attempted path: share/obs/obs-studio/themes/Dark.qss
Attempted path: /usr/share/obs/obs-studio/themes/Dark.qss
info: CPU Name: Intel(R) Core(TM) i5-4690K CPU @ 3.50GHz
info: CPU Speed: 2316.027MHz
info: Physical Cores: 4, Logical Cores: 4
info: Physical Memory: 11960MB Total, 3697MB Free
info: Kernel Version: Linux 4.15.0-130-generic
info: Distribution: "Ubuntu" "18.04"
info: Session Type: x11
info: Window System: X11.0, Vendor: The X.Org Foundation, Version: 1.19.6
info: Portable mode: false
Attempted path: share/obs/obs-studio/themes/Dark/no_sources.svg
Attempted path: /usr/share/obs/obs-studio/themes/Dark/no_sources.svg
QMetaObject::connectSlotsByName: No matching signal for on_advAudioProps_clicked()
QMetaObject::connectSlotsByName: No matching signal for on_advAudioProps_destroyed()
QMetaObject::connectSlotsByName: No matching signal for on_actionGridMode_triggered()
QMetaObject::connectSlotsByName: No matching signal for on_program_customContextMenuRequested(QPoint)
QMetaObject::connectSlotsByName: No matching signal for on_transitionRemove_clicked()
info: OBS 26.1.1 (linux)
info: ---------------------------------
info: ---------------------------------
info: audio settings reset:
    samples per sec: 48000
    speakers:        2
info: ---------------------------------
info: Initializing OpenGL...
info: Loading up OpenGL on adapter NVIDIA Corporation GeForce GTX 780/PCIe/SSE2
info: OpenGL loaded successfully, version 3.3.0 NVIDIA 450.102.04, shading language 3.30 NVIDIA via Cg compiler
info: ---------------------------------
info: video settings reset:
    base resolution:   1920x1080
    output resolution: 1280x720
    downscale filter:  Bicubic
    fps:               30/1
    format:            NV12
    YUV mode:          709/Partial
info: NV12 texture support not available
info: Audio monitoring device:
    name: Monitor of OBS_MONITOR
    id: OBS_MONITOR.monitor
info: ---------------------------------
warning: Failed to load 'en-US' text for module: 'decklink-captions.so'
warning: Failed to load 'en-US' text for module: 'decklink-ouput-ui.so'
libDeckLinkAPI.so: cannot open shared object file: No such file or directory
warning: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed
info: No blackmagic support
info: [obs-browser]: Version 2.9.1
info: [obs-browser]: CEF Version 76.1.13+gf19c584+chromium-76.0.3809.132
info: NVENC supported
info: FFMPEG VAAPI supported
info: VLC found, VLC video source enabled
info: [adv-ss] version: 5156c66b26ae1141db29e806ce663022828872b4
info: [adv-ss] trying '/home/josh'
info: [adv-ss] trying '/usr/lib'
info: [adv-ss] trying '/usr/local/lib'
info: [adv-ss] trying '/usr/lib/x86_64-linux-gnu'
info: [adv-ss] found curl library at '/usr/lib/x86_64-linux-gnu/libcurl.so.4'
info: [adv-ss] curl loaded successfully
info: ---------------------------------
info:   Loaded Modules:
info:     advanced-scene-switcher.so
info:     vlc-video.so
info:     text-freetype2.so
info:     rtmp-services.so
info:     obs-x264.so
info:     obs-vst.so
info:     obs-transitions.so
info:     obs-outputs.so
info:     obs-libfdk.so
info:     obs-filters.so
info:     obs-ffmpeg.so
info:     obs-browser.so
info:     linux-v4l2.so
info:     linux-pulseaudio.so
info:     linux-jack.so
info:     linux-decklink.so
info:     linux-capture.so
info:     linux-alsa.so
info:     image-source.so
info:     frontend-tools.so
info:     decklink-ouput-ui.so
info:     decklink-captions.so
info: ---------------------------------
error: os_dlopen(../obs-plugins/obs-browser->../obs-plugins/obs-browser.so): ../obs-plugins/obs-browser.so: cannot open shared object file: No such file or directory

info: ==== Startup complete ===============================================
info: Switched to Preview/Program mode
info: ------------------------------------------------
info: All scene data cleared
info: ------------------------------------------------
info: pulse-input: Server name: 'pulseaudio 11.1'
info: pulse-input: Audio format: s16le, 44100 Hz, 2 channels
info: pulse-input: Started recording from 'alsa_output.pci-0000_00_1b.0.analog-stereo.monitor'
info: pulse-am: Server name: 'pulseaudio 11.1'
error: pulse-am: An error occurred while getting the source info!
info: [Loaded global audio device]: 'Desktop Audio'
info:     - filter: 'Gain' (gain_filter)
info:     - monitoring: monitor and output
info: pulse-input: Server name: 'pulseaudio 11.1'
info: pulse-input: Audio format: s16le, 32000 Hz, 2 channels
info: pulse-input: Started recording from 'alsa_input.usb-046d_Logitech_Webcam_C925e_31BE4CDF-02.analog-stereo'
info: pulse-am: Server name: 'pulseaudio 11.1'
error: pulse-am: An error occurred while getting the source info!
info: [Loaded global audio device]: 'Mic/Aux'
info:     - monitoring: monitor and output
info: [Media Source 'TestVideo']: settings:
        ~snip~, more media sources
info: Switched to scene 'Cat Closed'
info: ------------------------------------------------
info: Loaded scenes:
info: - scene 'Desktop Commentary':
info:     - source: 'Mic/Aux' (pulse_input_capture)
         ~snip~, more scenes
info: ------------------------------------------------
info: adding 42 milliseconds of audio buffering, total audio buffering is now 42 milliseconds (source: Mic/Aux)

Attempted path: share/obs/obs-studio/images/overflow.png
Attempted path: /usr/share/obs/obs-studio/images/overflow.png
qt.svg: Cannot open file '/../forms/images/up.svg', because: No such file or directory
qt.svg: Cannot open file '/../forms/images/up.svg', because: No such file or directory
qt.svg: Cannot open file '/../forms/images/down.svg', because: No such file or directory
qt.svg: Cannot open file '/../forms/images/down.svg', because: No such file or directory
Segmentation fault (core dumped)

Here is a coredump link: https://gofile.io/d/OZiYnd Here is an alternate download link (different coredump, but produced the same way) https://files.catbox.moe/2jthm6.crash

No pressure to fix, but I'd be happy to try any fixes or provide more details.

WarmUpTill commented 3 years ago

First of all - thanks for reporting the issue!

I can't seem to produce a useable backtrace for some reason and cannot reproduce the issue in a Ubuntu 20 VM. Can you maybe try just running the latest build available just in case it was fixed already?

For example this one: https://github.com/WarmUpTill/SceneSwitcher/actions/runs/506410039

Just to make sure I understand the issue correctly: Does this issue only happen on a particular drop-down box on the audio tab or all of them? Does it apply to the other drop-down boxes on the other tabs as well?

Lytigas commented 3 years ago

Did some more digging using the nightly release you linked:

I tried to reproduce another way and found this: By messing around with many other controls at the same time (using scroll wheel and moving the mouse), I produced a segfault with this console output, which may be a good lead:

     ... Scene list ...
info: ------------------------------------------------
QXcbConnection: XCB error: 3 (BadWindow), sequence: 552, resource id: 9104064, major code: 40 (TranslateCoords), minor code: 0
Attempted path: share/obs/obs-studio/images/overflow.png
Attempted path: /usr/share/obs/obs-studio/images/overflow.png
qt.svg: Cannot open file '/home/josh/forms/images/up.svg', because: No such file or directory
qt.svg: Cannot open file '/home/josh/forms/images/up.svg', because: No such file or directory
qt.svg: Cannot open file '/home/josh/forms/images/down.svg', because: No such file or directory
qt.svg: Cannot open file '/home/josh/forms/images/down.svg', because: No such file or directory
warning: [adv-ss] failed to attach volmeter to source (null)
warning: [adv-ss] failed to attach volmeter to source (null)
Segmentation fault (core dumped)

The printout could be a race condition as I can't seem to get it a second time. Or, it could be two separate issues.

On further testing, I managed to produce seemingly the same segfault more consistently, albeit without the printout: Create many entries in the audio tab by hitting "+" many times. Place the mouse near the above/below input box of one of them. Scroll up and down rapidly while moving the mouse around. This will simultaneously alter the "above/below" input, the threshold, and scroll the window. Eventually, this often segfaults. This seems so nasty to debug I don't think it's worth the time.

Back to the main issue -- I was going to record something in rr so I could send it to you, but OBS needs the GPU and that doesn't seem to work in RR. For now, I have this backtrace for you, produced as in the original report (selecting something from the source dropdown):

(gdb) backtrace
#0  0x00007ffff2f7efd0 in __GI___pthread_mutex_lock (mutex=0x79) at ../nptl/pthread_mutex_lock.c:67
#1  0x00007ffff49e6427 in obs_volmeter_remove_callback () at /usr/lib/libobs.so.0
#2  0x0000555555725c52 in  ()
#3  0x0000555555725cb9 in  ()
#4  0x00007fff8ee413dc in AudioSwitchWidget::UpdateVolmeterSource() (this=this@entry=0x55555c6b1a10) at /home/runner/work/SceneSwitcher/SceneSwitcher/UI/frontend-plugins/SceneSwitcher/src/switch-audio.cpp:520
#5  0x00007fff8ee41611 in AudioSwitchWidget::SourceChanged(QString const&) (this=0x55555c6b1a10, text=...) at /home/runner/work/SceneSwitcher/SceneSwitcher/UI/frontend-plugins/SceneSwitcher/src/switch-audio.cpp:545
#6  0x00007ffff3d8c555 in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#7  0x00007ffff4ebfd05 in QComboBox::currentTextChanged(QString const&) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#8  0x00007ffff4ec1bfb in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#9  0x00007ffff4ec302c in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#10 0x00007ffff4ec31c1 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#11 0x00007ffff4ec8c8d in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#12 0x00007ffff3d8c555 in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#13 0x00007ffff4ec02f9 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#14 0x00007ffff3d5d5bc in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#15 0x00007ffff4dbb815 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#16 0x00007ffff4dc365f in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#17 0x00007ffff3d5d8d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#18 0x00007ffff4dc2632 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#19 0x00007ffff4e14ea5 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#20 0x00007ffff4e177da in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#21 0x00007ffff4dbb83c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#22 0x00007ffff4dc3104 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#23 0x00007ffff3d5d8d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#24 0x00007ffff431f583 in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#25 0x00007ffff4321055 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#26 0x00007ffff42f82eb in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#27 0x00007fffdbabd676 in  () at /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
#28 0x00007ffff3d5b90a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#29 0x00007ffff4fa5f17 in QDialog::exec() () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#30 0x00007fff8edcf5fa in <lambda()>::operator() (__closure=<optimized out>) at /home/runner/work/SceneSwitcher/SceneSwitcher/UI/frontend-plugins/SceneSwitcher/src/advanced-scene-switcher.cpp:742
#31 0x00007fff8edcf5fa in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, InitSceneSwitcher()::<lambda()> >::call (f=..., arg=<optimized out>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:130
#32 0x00007fff8edcf5fa in QtPrivate::Functor<InitSceneSwitcher()::<lambda()>, 0>::call<QtPrivate::List<>, void> (f=..., arg=<optimized out>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:240
#33 0x00007fff8edcf5fa in QtPrivate::QFunctorSlotObject<InitSceneSwitcher()::<lambda()>, 0, QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void **, bool *) (which=<optimized out>, this_=<optimized out>, r=<optimized out>, a=<optimized out>, ret=<optimized out>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject_impl.h:168
#34 0x00007ffff3d8c66f in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#35 0x00007ffff4db5122 in QAction::triggered(bool) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#36 0x00007ffff4db780c in QAction::activate(QAction::ActionEvent) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#37 0x00007ffff4f340fc in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#38 0x00007ffff4f3b5ab in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#39 0x00007ffff4f3c3d3 in QMenu::mouseReleaseEvent(QMouseEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#40 0x00007ffff4dfa048 in QWidget::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#41 0x00007ffff4f3e6fb in QMenu::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#42 0x00007ffff4dbb83c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#43 0x00007ffff4dc365f in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#44 0x00007ffff3d5d8d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#45 0x00007ffff4dc2632 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#46 0x00007ffff4e14ea5 in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#47 0x00007ffff4e177da in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#48 0x00007ffff4dbb83c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#49 0x00007ffff4dc3104 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#50 0x00007ffff3d5d8d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#51 0x00007ffff431f583 in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#52 0x00007ffff4321055 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#53 0x00007ffff42f82eb in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#54 0x00007fffdbabd676 in  () at /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
#55 0x00007ffff3d5b90a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
---Type <return> to continue, or q <return> to quit---frame 1
#56 0x00007ffff3d649b4 in QCoreApplication::exec() () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#57 0x00005555555da972 in main ()

Next, I plan to recompile OBS and the plugin with debug symbols enabled so I can give you some better info. I'm commenting this now in case I get interrupted and it takes a while to finish.

Lytigas commented 3 years ago

This is weird.

In a debug build of OBS from master (c38cbb1), the segfault does not occur. Instead, I get two lines of debug output

debug: obs_source_get_name: Null 'source' parameter
debug: obs_volmeter_remove_callback: Null 'volmeter' parameter

The first line appears when the entry in the audio menu is created, and the second when a source is selected.

In a non-debug build of OBS master, the issue also appears to be fixed. In fact, all builds I tried of OBS from source, going all the way back to the 26.1.1 tag, and even the debian package tarball itself, don't reproduce the issue.

It must be caused by a build parameter then, right? Could be, here are my build parameters (build is inside a bionic Docker container):

cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="/opt/obs_build/install" ..

and here are the ones in the debian.tar.xz:

dh_auto_configure -- -DOBS_VERSION_OVERRIDE="26.1.1" -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="../cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_linux64_minimal" -DUSE_QT_LOOP=TRUE

I also tried adding -DUSE_QT_LOOP=TRUE, no change. Unless it's something with CEF or portable mode, I'm lost.

I have no idea how this is fixed in OBS itself, but this explains why you couldn't reproduce.

Regardless of the root cause, it's probably not anything in this plugin. I appreciate any effort you may have put into resolving this, although I feel bad for wasting your time with what seems to have been an OBS [packaging] issue :)

I'm closing on that theory. If you think it might actually be caused by this plugin, I'd be happy to help investigate further.

WarmUpTill commented 3 years ago

This very strange indeed and I also don't have an explanation, what could have caused this, but I am glad that it is resolved (for) now! :)

The following messages are expected on a newly added audio tab entry as the connected audio source is initialized to nullptr:

debug: obs_source_get_name: Null 'source' parameter
debug: obs_volmeter_remove_callback: Null 'volmeter' parameter

I might add some nullptr checks in future to avoid these misleading messages.

Anyways, thanks for all the effort you put into analyzing this further!