From 132ca89053ac9d8f3f88b79bd5d5b3469e354afc Mon Sep 17 00:00:00 2001 From: Debian User Date: Thu, 17 Oct 2013 10:04:07 +0800 Subject: [PATCH] Allow only one camera on at a time. This fixes a crash if both cameras are activated at once. --- server/image.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/image.c b/server/image.c index a24d091..1d35264 100644 --- a/server/image.c +++ b/server/image.c @@ -4,7 +4,8 @@ #include #include -CvCapture *captures[2] = {0}; +CvCapture *capture; +int captureID = -1; void Image_Handler(FCGIContext * context, char * params) { @@ -24,10 +25,12 @@ void Image_Handler(FCGIContext * context, char * params) return; } - CvCapture *capture = captures[num]; - if (capture == NULL) { + if (captureID != num) { + if (captureID >= 0) { + cvReleaseCapture(&capture); + } capture = cvCreateCameraCapture(num); - captures[num] = capture; + captureID = num; } cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width); -- 2.20.1