gl: Fix crash in cocoa due to race in gst_gl_context_activate()
authorNirbheek Chauhan <nirbheek@centricular.com>
Mon, 16 Jan 2023 10:25:56 +0000 (15:55 +0530)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 17 Jan 2023 21:56:41 +0000 (21:56 +0000)
commited1bdf9b1aa4effe408ad41ac81eaf9b079208ba
treea6bef2097f68556834d6eb627af6dfc2691f05de
parent18f313d317267603ca42d87eadd9f9d3cc7f8624
gl: Fix crash in cocoa due to race in gst_gl_context_activate()

We create a new context in `gst_gl_context_create_thread()` and then
activate it on the current thread. Thereafter we assume that the
current thread continues to be the active thread for that context and
call `gst_gl_context_fill_info()` which asserts that the current
thread is the active thread.

However, if at the same time a different thread calls
`send_message_async()`, it will call into
`gst_gl_window_cocoa_send_message_async()` which will schedule the
message to be invoked using GCD. That anonymous function will also
call `gst_gl_context_activate()`, which creates a race, which can lead
to:

```
gst_gl_context_fill_info: assertion 'context->priv->active_thread == g_thread_self ()' failed
```

Fix it by using `gst_gl_context_thread_add()` to invoke `fill_info()`
on the context.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3732>
subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcontext.c