From 4682cfb61b870b8488717b25c370c2bbfe98fbac Mon Sep 17 00:00:00 2001 From: Palana Date: Sun, 4 May 2014 21:01:46 +0200 Subject: [PATCH] Fix an issue with async (video) source destruction obs_source_output_video can cause cached frames to be freed twice if called with a partially destroyed source, among other undesirable effects; freeing the source private data right after the destroy signal has been processed ensures proper behavior --- libobs/obs-source.c | 6 +++--- libobs/obs-source.h | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 620161ccf..3854ee58b 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -211,6 +211,9 @@ void obs_source_destroy(struct obs_source *source) obs_source_dosignal(source, "source_destroy", "destroy"); + if (source->context.data) + source->info.destroy(source->context.data); + if (source->filter_parent) obs_source_filter_remove(source->filter_parent, source); @@ -225,9 +228,6 @@ void obs_source_destroy(struct obs_source *source) texture_destroy(source->async_texture); gs_leavecontext(); - if (source->context.data) - source->info.destroy(source->context.data); - for (i = 0; i < MAX_AV_PLANES; i++) bfree(source->audio_data.data[i]); diff --git a/libobs/obs-source.h b/libobs/obs-source.h index 5f40d8799..479fd4b44 100644 --- a/libobs/obs-source.h +++ b/libobs/obs-source.h @@ -132,7 +132,12 @@ struct obs_source_info { */ void *(*create)(obs_data_t settings, obs_source_t source); - /** Destroys the private data for the source */ + /** + * Destroys the private data for the source + * + * Async sources must not call obs_source_output_video after returning + * from destroy + */ void (*destroy)(void *data); /** Returns the width of the source. Required if this is an input