1
0
Эх сурвалжийг харах

libobs: Check for removals in obs_enum_sources

Checks for removals while enumerating, which allows one to be able to
remove a source in the enumeration.
jp9000 10 жил өмнө
parent
commit
4ed1ee7009
1 өөрчлөгдсөн 9 нэмэгдсэн , 0 устгасан
  1. 9 0
      libobs/obs.c

+ 9 - 0
libobs/obs.c

@@ -1174,8 +1174,17 @@ void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t*), void *param)
 
 	for (size_t i = 0; i < obs->data.user_sources.num; i++) {
 		struct obs_source *source = obs->data.user_sources.array[i];
+		size_t prev_size = obs->data.user_sources.num;
+
 		if (!enum_proc(param, source))
 			break;
+
+		/* To ensure the save data is always consistent, we always want
+		 * to traverse this list forward.  Because of that, we have to
+		 * manually check to see if the source was removed in the
+		 * enumeration proc and adjust it accordingly */
+		if (obs->data.user_sources.num < prev_size)
+			i--;
 	}
 
 	pthread_mutex_unlock(&obs->data.user_sources_mutex);