From ab65df74e0f3b1b7f8ef62101e8a1906422bfd33 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 10 Apr 2015 19:09:18 -0700 Subject: [PATCH] libobs: Increment new frame ref when first copying When caching a new frame, keep a reference to the frame while copying to ensure that the frame is not potentially destroyed for whatever reason while that data is being copied. --- libobs/obs-source.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index a6d0d3ee2..566407d56 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1687,9 +1687,17 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source, da_push_back(source->async_cache, &new_af); } + os_atomic_inc_long(&new_frame->refs); + pthread_mutex_unlock(&source->async_mutex); copy_frame_data(new_frame, frame); + + if (os_atomic_dec_long(&new_frame->refs) == 0) { + obs_source_frame_destroy(new_frame); + new_frame = NULL; + } + return new_frame; }