Selaa lähdekoodia

Release IOSurface only after it is no longer in use (e.g. by a texture)

Palana 11 vuotta sitten
vanhempi
sitoutus
a439177a58
1 muutettua tiedostoa jossa 13 lisäystä ja 1 poistoa
  1. 13 1
      test/test-input/test-desktop.m

+ 13 - 1
test/test-input/test-desktop.m

@@ -39,6 +39,12 @@ static void destroy_display_stream(struct display_capture *dc)
 		dc->current = NULL;
 		dc->current = NULL;
 	}
 	}
 
 
+	if (dc->prev) {
+		IOSurfaceDecrementUseCount(dc->prev);
+		CFRelease(dc->prev);
+		dc->prev = NULL;
+	}
+
 	if (dc->disp) {
 	if (dc->disp) {
 		CFRelease(dc->disp);
 		CFRelease(dc->disp);
 		dc->disp = NULL;
 		dc->disp = NULL;
@@ -182,13 +188,19 @@ static void display_capture_video_render(void *data, effect_t effect)
 
 
 	pthread_mutex_lock(&dc->mutex);
 	pthread_mutex_lock(&dc->mutex);
 
 
-	if (dc->prev != dc->current) {
+	if (dc->current && dc->prev != dc->current) {
 		if (dc->tex)
 		if (dc->tex)
 			texture_rebind_iosurface(dc->tex, dc->current);
 			texture_rebind_iosurface(dc->tex, dc->current);
 		else
 		else
 			dc->tex = gs_create_texture_from_iosurface(
 			dc->tex = gs_create_texture_from_iosurface(
 					dc->current);
 					dc->current);
+
+		if (dc->prev) {
+			IOSurfaceDecrementUseCount(dc->prev);
+			CFRelease(dc->prev);
+		}
 		dc->prev = dc->current;
 		dc->prev = dc->current;
+		dc->current = NULL;
 	}
 	}
 
 
 	if (!dc->tex) goto fail;
 	if (!dc->tex) goto fail;