obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

OBS crashes with explicit sync on wayland

Open mahkoh opened this issue 1 year ago • 23 comments

Operating System Info

Other

Other OS

Arch Linux

OBS Studio Version

30.1.2

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://obsproject.com/logs/WQGyYH2S1OMk7op4

OBS Studio Crash Log URL

No response

Expected Behavior

OBS does not crash.

Current Behavior

OBS crashes.

Steps to Reproduce

Start OBS under a wayland compositor that supports explicit sync and with graphics drivers that support explicit sync. With up-to-date nvidia drivers, that should always be the case. With mesa, you will also have to set the environment variable MESA_LOADER_DRIVER_OVERRIDE=zink to ensure that vulkan is being used under the hood.

After starting OBS, right click on the preview and select Windowed Projector (Preview). You might have to repeat this several times.

OBS crashes.

Anything else we should know?

I am reasonably certain that this is caused by the following series of events:

  1. OBS creates a QT window.
  2. OBS extracts the underlying wl_surface.
  3. OBS uses that wl_surface to create an OpenGL context.
  4. Later, QT tries to commit a SHM buffer to that wl_surface. Possibly due to a resize event. Since QT does not know anything about the OpenGL context, this crashes.

The last step is unsound. QT must not not manipulate the surface buffer while the surface is owned by an OpenGL or Vulkan context. I believe that that much is required by the OpenGL and Vulkan specifications.

The question is if QT is in the wrong here (although I don't see how, QT seems to know nothing about OBS creating on OpenGL context) or if this is an OBS bug because OBS creates an OpenGL context without properly informing QT about this.

@davidedmundson can you comment on the above?

mahkoh avatar Jul 23 '24 18:07 mahkoh

Without remembering any OBS code:

  • if you're making a QWidget then doing myWidget->create / myWidget->winId to get a window that's an OBS bug, as you've got Qt and OBS drawing into the same thing

  • if you're making a QWindow directly and Qt is suddenly attaching buffers, that's a Qt bug and I'll look into it further.

davidedmundson avatar Jul 23 '24 18:07 davidedmundson

OBS draws directly into the QWidget for all displays (OBS rendered content), perhaps the project is using a different setting that causes the shm to be attached.

kkartaltepe avatar Aug 22 '24 02:08 kkartaltepe

I am also experiencing this issue or something similar. It seems to somewhat fix itself but it has reappeared today after installing openrazer. 2024-09-02 04-46-41.txt

Defarius avatar Sep 02 '24 12:09 Defarius

I posted a question about mixing app and GL buffer attaches on wayland that might be relevant here: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/211

amshafer avatar Sep 05 '24 01:09 amshafer

I'm pretty sure removing https://github.com/obsproject/obs-studio/blob/master/UI/window-projector.cpp#L41-L44 will resolve this for people experiencing issues. Unfortunately a real solution is a bit more complicated assuming this really does work.

kkartaltepe avatar Sep 05 '24 01:09 kkartaltepe

I believe the problematic code also causes the following issue: When resizing a projector window, the window becomes transparent.

https://github.com/user-attachments/assets/b42f75c0-20e7-40f3-b824-71a3de5eddca

mahkoh avatar Oct 11 '24 13:10 mahkoh

Can confirm this still occurs under the Flatpak version on KDE Plasma 6.2.0/QT Ver 6.7.2 / Nvidia 1080ti (driver 560.35.03).

When trying to open the windowed projector I get this:

warning: Creating a popup with a parent, QWidgetWindow(0x5586428673e0, name="OBSBasicWindow") which does not match the current topmost grabbing popup, QWidgetWindow(0x558644e94190, name="QMenuClassWindow") With some shell surface protocols, this is not allowed. The wayland QPA plugin is currently handling it by setting the parent to the topmost grabbing popup. Note, however, that this may cause positioning errors and popups closing unxpectedly. Please fix the transient parent of the popup.
wp_linux_drm_syncobj_surface_v1@103: error 4: explicit sync is used, but no acquire point is set
warning: The Wayland connection experienced a fatal error: Protocol error

And then OBS crashes

iotku avatar Oct 12 '24 04:10 iotku

@kkartaltepe I tried building a Flatpak from master today with the "WA_PaintOnScreen" part removed as you suggested. At first sight, it works nicely for me under Wayland (KDE 6.2.1), including resizing the windowed projector smoothly. When running this modified version under X11, however, resizing the projector window freezes rendering in OBS until after I stop resizing the window, causing framedrops.

I don't know what possible other drawbacks there could be when running this modified version under Wayland, but if it works nicely, could it be a solution to conditionally set WA_PaintOnScreen if running under X11 only?

Edit: Here's a suggestion for conditionally setting the attribute: https://github.com/OchiLive/obs-studio/commit/d2189ab7461381f1f1406e0053e0446d34976fba - feel free to try it out and let me know if it may be worthwhile to make a pull request out of it. Maybe it should be tested in various desktop environments.

ochilan avatar Oct 19 '24 10:10 ochilan

i get this error on OBS 31.0.1, any news about it ?

mrdev023 avatar Feb 02 '25 17:02 mrdev023

i get this error on OBS 31.0.1, any news about it ?

This is not an OBS issue, I get exactly the same problem using looking-glass.io, the fix (well workaround) is to add "__NV_DISABLE_EXPLICIT_SYNC=1" to your environment variables or downgrade egl-wayland to version 1.1.13 (but I don't recommend that).

thingi avatar Feb 03 '25 11:02 thingi

Yes this is an obs issue and we have a tentative fix pending, however there are even more bugs and broken behavior in Qt with the "correct" qwidgets. So until we find suitable workarounds to avoid breaking more people you will have to workaround your nvidia situation.

kkartaltepe avatar Feb 03 '25 16:02 kkartaltepe

@kkartaltepe what other explicit sync related Qt issues are you referring to?

amshafer avatar Feb 10 '25 14:02 amshafer

The remaining issues are unrelated to explicit sync, and just the regular wayland issues that qt and gnome cant agree on how the wayland protocol works, or just plain bugs in qt.

kkartaltepe avatar Feb 10 '25 15:02 kkartaltepe

If there are bugs in Qt + Wayland please do reach out to the QtWayland maintainer (me), I can help fix anything either here or upstream.

davidedmundson avatar Feb 10 '25 16:02 davidedmundson

You are free to remove the workaround from #11773 and test the fullscreen/windowing functionality on gnome. Its unlikely I would ever have the time to try and craft a minimal reproducer for a Qt bug report, and its pretty low value since any fixes in qt wont be usable by downstreams like us for at least 2 years anyway due to distro and qt release processes.

kkartaltepe avatar Feb 11 '25 04:02 kkartaltepe

Having an issue quite similar to #12007 where using Fullscreen Projector (Preview) is now crashing for me. Log: https://pastebin.com/zFwEHhJ0 Since it started happening, the only change I recall making is updating my graphics drivers from 570 to 575. I walked them back, but I'm still experiencing this.

Edit: I've tried some of the suggested workarounds to no avail. I've also updated OBS too, here's the log for that: https://pastebin.com/swYfGjci I went back to a previous version in hopes that would work as well.

nek0d3r avatar Jul 16 '25 17:07 nek0d3r

The crash still occurs on Debian 13 using Wayland with Nvidia 580.76.05 and OBS 31.1.2. The workaround is a lifesaver, but like others.

ogmkp avatar Aug 27 '25 01:08 ogmkp

Unfortunately there are more bugs in Qts wayland platform that cause their recommended approach to solve this to break for everyone on gnome, regardless of their gpu vendor. So until that is resolved its better to let nvidia users work around their issue.

In the meanwhile we have provided Qt with a minimal reproducer for this a few months ago and given they've mentioned their commitment to fixing wayland bugs I'm sure it will be resolved soon and we can commit a fix for nvidia users.

kkartaltepe avatar Aug 27 '25 04:08 kkartaltepe

Unfortunately there are more bugs in Qts wayland platform that cause their recommended approach to solve this to break for everyone on gnome, regardless of their gpu vendor.

Can you share some details of that somewhere.

davidedmundson avatar Aug 27 '25 07:08 davidedmundson

Unfortunately there are more bugs in Qts wayland platform that cause their recommended approach to solve this to break for everyone on gnome, regardless of their gpu vendor.

Can you share some details of that somewhere.

QTBUG-134711

kkartaltepe avatar Aug 29 '25 02:08 kkartaltepe

We do not recommend you use unsupported OBS configurations, if you are here looking for a workaround you can disable explicit sync in the nvidia drivers as recommended above using the environment variable __NV_DISABLE_EXPLICIT_SYNC=1

kkartaltepe avatar Oct 15 '25 01:10 kkartaltepe