Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libobs/build/libobs.core-source+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "libobs/build/libobs.pch.h"

#include "libobs/obs-canvas-channel-fields.c.h"
#include "libobs/obs-canvas-clear-mix.c.h"
#include "libobs/obs-canvas-flags-fields.c.h"
#include "libobs/obs-canvas-public-constructors.c.h"
#include "libobs/obs-canvas-readonly-fields.c.h"
Expand Down
38 changes: 38 additions & 0 deletions libobs/obs-canvas-clear-mix.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/******************************************************************************
Copyright (C) 2025 by Dennis Sädtler <saedtler@twitch.tv>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "libobs/build/libobs.pch.h"

/* Free canvas mix (if any) */
void obs_canvas_clear_mix(obs_canvas_t *canvas)
{
if (!canvas->mix)
return;

pthread_mutex_lock(&obs->video.mixes_mutex);
for (size_t i = 0; i < obs->video.mixes.num; i++) {
struct obs_core_video_mix *mix = obs->video.mixes.array[i];
if (mix == canvas->mix) {
da_erase(obs->video.mixes, i);
obs_free_video_mix(mix);
break;
}
}
pthread_mutex_unlock(&obs->video.mixes_mutex);

canvas->mix = NULL;
}
20 changes: 0 additions & 20 deletions libobs/obs-canvas.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,6 @@ void obs_canvas_destroy(obs_canvas_t *canvas)

/*** Internal API ***/

/* Free canvas mix (if any) */
void obs_canvas_clear_mix(obs_canvas_t *canvas)
{
if (!canvas->mix)
return;

pthread_mutex_lock(&obs->video.mixes_mutex);
for (size_t i = 0; i < obs->video.mixes.num; i++) {
struct obs_core_video_mix *mix = obs->video.mixes.array[i];
if (mix == canvas->mix) {
da_erase(obs->video.mixes, i);
obs_free_video_mix(mix);
break;
}
}
pthread_mutex_unlock(&obs->video.mixes_mutex);

canvas->mix = NULL;
}

/* Clear mixes attached to canvases */
void obs_free_canvas_mixes(void)
{
Expand Down
34 changes: 34 additions & 0 deletions test/cmocka/build/test-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,34 @@
}
]
},
"test_canvas_clear_mix": {
"sources": [
"test/cmocka/test_canvas_clear_mix.c",
{
"path": "test/cmocka/canvas-clear-mix-null-host-linux.c",
"requires": "OS_LINUX"
}
],
"libraries": [
"OBS::libobs",
"OBS::caption",
"Uthash::Uthash",
"OBS::native-test-cmocka",
{
"name": "OBS::w32-pthreads",
"requires": "OS_WINDOWS"
}
],
"header_libraries": [
"SIMDe::SIMDe"
],
"compile_options": [
{
"name": "-DCANVAS_CLEAR_MIX_NULL_PROBE",
"requires": "OS_LINUX"
}
]
},
"test_canvas_destroy_scene_refs": {
"sources": [
"test/cmocka/test_canvas_destroy_scene_refs.c"
Expand Down Expand Up @@ -22680,6 +22708,12 @@
"${target}"
]
},
"test_canvas_clear_mix": {
"target": "test_canvas_clear_mix",
"command": [
"${target}"
]
},
"test_canvas_destroy_scene_refs": {
"target": "test_canvas_destroy_scene_refs",
"command": [
Expand Down
32 changes: 32 additions & 0 deletions test/cmocka/canvas-clear-mix-null-host-linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Isolate the existing NULL-canvas fault before any threads are started. */
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
#include <obs.h>

void canvas_clear_mix_null_probe(void (*clear)(obs_canvas_t *));

void canvas_clear_mix_null_probe(void (*clear)(obs_canvas_t *))
{
pid_t child = fork();
assert_true(child >= 0);
if (child == 0) {
const struct rlimit no_core = {0, 0};
if (setrlimit(RLIMIT_CORE, &no_core) != 0)
_exit(2);
signal(SIGSEGV, SIG_DFL);
signal(SIGBUS, SIG_DFL);
/* Characterized, not endorsed: NULL is outside the C valid domain. */
clear(NULL);
_exit(0);
}
int status = 0;
assert_int_equal(waitpid(child, &status, 0), child);
assert_true(WIFSIGNALED(status));
assert_true(WTERMSIG(status) == SIGSEGV || WTERMSIG(status) == SIGBUS);
}
Loading
Loading