falkTX / Carla

Audio plugin host
https://kx.studio/carla
1.62k stars 147 forks source link

some plugin UIs crash on wayland when loaded via carla lib #1527

Open alex-tee opened 3 years ago

alex-tee commented 3 years ago

program gets killed when trying to load a plugin's UI on wayland. this can be replicated by trying to open fluida in zrythm

cannot replicate the issue in ildaeil

Messages:

Plugin with id 0 triggered parameter 8 update while UI is hidden
Plugin with id 0 triggered parameter 11 update while UI is hidden
Plugin with id 0 triggered parameter 7 update while UI is hidden
Plugin with id 0 triggered parameter 10 update while UI is hidden
Plugin with id 0 triggered parameter 9 update while UI is hidden
Plugin with id 0 triggered parameter 5 update while UI is hidden
Plugin with id 0 triggered parameter 1 update while UI is hidden
Plugin with id 0 triggered parameter 4 update while UI is hidden
Plugin with id 0 triggered parameter 2 update while UI is hidden
Plugin with id 0 triggered parameter 6 update while UI is hidden
Plugin with id 0 triggered parameter 3 update while UI is hidden
Plugin with id 0 triggered parameter 0 update while UI is hidden
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  34
  Current serial number in output stream:  34
[Thread 0x7fffeae29640 (LWP 93299) exited]
JUCE Assertion failure in juce_Singleton.h:50
JUCE Assertion failure in juce_Singleton.h:50
Carla assertion failure: "! lib.canDelete" in file ../../utils/CarlaLibCounter.hpp, line 46
Carla assertion failure: "! lib.canDelete" in file ../../utils/CarlaLibCounter.hpp, line 46
[Thread 0x7fff877fe640 (LWP 93483) exited]
[Thread 0x7fff86ffd640 (LWP 93482) exited]
[Thread 0x7fff9e7fc640 (LWP 93481) exited]
[Thread 0x7fff9effd640 (LWP 93480) exited]
[Thread 0x7fff87fff640 (LWP 93466) exited]
[Thread 0x7fff9dffb640 (LWP 93442) exited]
[Thread 0x7fffd7743640 (LWP 93441) exited]
[Thread 0x7fff9cff9640 (LWP 93440) exited]
[Thread 0x7fff9f7fe640 (LWP 93439) exited]
[Thread 0x7fff9d7fa640 (LWP 93380) exited]
[Thread 0x7fff9ffff640 (LWP 93366) exited]
[Thread 0x7fffb12d2640 (LWP 93364) exited]
[Thread 0x7fffb1ad3640 (LWP 93363) exited]
[Thread 0x7fffbdffe640 (LWP 93362) exited]
[Thread 0x7fffbb2d1640 (LWP 93361) exited]
[Thread 0x7fffd6f42640 (LWP 93360) exited]
[Thread 0x7fffeb7fe640 (LWP 93296) exited]
[Thread 0x7fffebfff640 (LWP 93294) exited]
[Thread 0x7ffff0a7f640 (LWP 93293) exited]
[Thread 0x7ffff1280640 (LWP 93292) exited]
[Thread 0x7ffff190ec00 (LWP 93288) exited]
[Inferior 1 (process 93288) exited with code 01]

related code: https://git.zrythm.org/zrythm/zrythm/src/branch/gtk4/src/plugins/carla_native_plugin.c#L1400

alex-tee commented 3 years ago

3BandEQ says this (on Wayland, not XWayland):

X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  30
  Current serial number in output stream:  30

this may be related to https://gitlab.gnome.org/GNOME/gtk/-/issues/4441 (which is on XWayland but seems related)

alex-tee commented 3 years ago

it looks like this happens with bridged UIs as well.

DrumGizmo on Wayland using the ENGINE_OPTION_PREFER_UI_BRIDGES option:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  31
  Current serial number in output stream:  31
falkTX commented 3 years ago

3BandEQ says this (on Wayland, not XWayland):

X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  30
  Current serial number in output stream:  30

this may be related to https://gitlab.gnome.org/GNOME/gtk/-/issues/4441 (which is on XWayland but seems related)

This is a different one. Seems like creating a GL context is failing entirely.

The others are about giving input focus, something that could happen on X11 too.

benjamin-otte commented 2 years ago

3BandEQ says this (on Wayland, not XWayland):

X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  30
  Current serial number in output stream:  30

this may be related to https://gitlab.gnome.org/GNOME/gtk/-/issues/4441 (which is on XWayland but seems related)

GTK dev checking in, @alex-tee just asked me about this:

This happens because Wayland uses EGL (and so does GTK on Wayland) and the X server (XWayland in this case) gets confused it both an EGL and a GLX context are current at the same time.

You can in theory fix that if you clear the current other context (and pray that Mesa/nvidia drivers don't fall over). However, neither EGL code nor GLX code usually is aware of this, so they don't do that and then explode.

Clearing contexts is also slow, so it's not recommended to excessively clear contexts.

alex-tee commented 2 years ago

it looks like this happens with bridged UIs as well.

DrumGizmo on Wayland using the ENGINE_OPTION_PREFER_UI_BRIDGES option:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  31
  Current serial number in output stream:  31

the X_SetInputFocus issue with fluida and the one I quoted above are fixed when clearing GTK's opengl context before running ui_idle() and then returning it.

3BandEQ says this (on Wayland, not XWayland):

X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  5 (X_GLXMakeCurrent)
  Serial number of failed request:  30
  Current serial number in output stream:  30

this may be related to https://gitlab.gnome.org/GNOME/gtk/-/issues/4441 (which is on XWayland but seems related)

this happens when attempting to open the UI with carla_show_custom_ui() and is also fixed by clearing GTK's GL context before calling that and then returning the context afterwards

@benjamin-otte is it normal that GTK has a current context in source functions added with g_timeout_add() or is it a bug? I wouldn't expect there to be a current context in random source functions because GTK is not doing anything OpenGL related at that time but I might be mistaken.

This is how I check if there is a current context and how I clear it btw:

static GdkGLContext *
clear_gl_context (void)
{
  if (string_is_equal (
        z_gtk_get_gsk_renderer_type (),
        "GL"))
    {
      GdkGLContext * context =
        gdk_gl_context_get_current ();
      if (context)
        {
          g_warning ("have GL context - clearing");
          g_object_ref (context);
          gdk_gl_context_clear_current ();
        }
      return context;
    }

  return NULL;
}

static void
return_gl_context (
  GdkGLContext * context)
{
  if (context)
    {
      g_debug ("RETURNING CONTEXT");
      gdk_gl_context_make_current (context);
      g_object_unref (context);
    }
}
benjamin-otte commented 2 years ago

@benjamin-otte is it normal that GTK has a current context

Yes.

Unsetting a context is expensive, so why do it?

alex-tee commented 2 years ago

@benjamin-otte is it normal that GTK has a current context

Yes.

Unsetting a context is expensive, so why do it?

Makes sense, thanks.

alex-tee commented 2 years ago

Sorry, I made a mistake about the X_SetInputFocus thing. I was on X11 when I was testing that. The GL issue is fixed though. I can reproduce the X_SetInputFocus error with Fluida and DrumGizmo on Wayland.

In both Fluida and DrumGizmo, the UI gets displayed and fails on the 2nd ui_idle() call:

(zrythm:1226570): zrythm-WARNING **: 15:08:21.556: (clear_gl_context:119): have GL context - clearing
(zrythm:1226570): zrythm-DEBUG: 15:08:21.556: (carla_plugin_tick_cb:154): calling ui_idle()...
(zrythm:1226570): zrythm-DEBUG: 15:08:21.571: (carla_plugin_tick_cb:157): done calling ui_idle()
(zrythm:1226570): zrythm-DEBUG: 15:08:21.571: (return_gl_context:135):      RETURNING CONTEXT
(zrythm:1226570): zrythm-WARNING **: 15:08:21.572: (clear_gl_context:119): have GL context - clearing
(zrythm:1226570): zrythm-DEBUG: 15:08:21.572: (carla_plugin_tick_cb:154): calling ui_idle()...
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  34
  Current serial number in output stream:  34
falkTX commented 2 years ago

note that with the latest commit, I cannot reproduce at all. so if the issue is still there, we need to come up with a simpler way to test case things like this

alex-tee commented 2 years ago

On latest commit I can reproduce this with Fluida, DrumGizmo, ZLFO, sfizz, Surge (all LV2) in Zrythm with the host lib. I can open DrumGizmo when I run carla standalone with carla -platform wayland-egl so the issue is likely specific to a GTK4 host. I will try to see which of XSetInputFocus causes it in source/utils/CarlaPluginUI.cpp like you said, or maybe we can look at this after I port Chibi to GTK4

alex-tee commented 2 years ago

On latest commit I can reproduce this with Fluida, DrumGizmo, ZLFO, sfizz, Surge (all LV2) in Zrythm with the host lib

we need to come up with a simpler way to test case things like this

@falkTX I can now reproduce these exact same issues with the new Chibi (on commit bc2145a0b45129565514bf377063bd1cf5128389) on Wayland so it's definitely an issue related to GTK4 hosts:

gdb -ex run --args build/src/Chibi http://drumgizmo.org/lv2
...
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  31
  Current serial number in output stream:  31
gdb -ex run --args build/src/Chibi https://github.com/brummer10/Fluida.lv2
...
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  34
  Current serial number in output stream:  34
mara004 commented 1 year ago

Same problem on Fedora 37 when attempting to show certain plugin GUIs (e.g. calf, x42). Setting QT_QPA_PLATFORM=xcb successfully works around the issue.