From: Debian User Date: Thu, 17 Oct 2013 02:04:07 +0000 (+0800) Subject: Allow only one camera on at a time. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=132ca89053ac9d8f3f88b79bd5d5b3469e354afc;p=matches%2FMCTX3420.git Allow only one camera on at a time. This fixes a crash if both cameras are activated at once. --- 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);