From 143345b8c8232a67165920365f4bb07e82fd6ae5 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 20 May 2014 07:28:26 -0500 Subject: [PATCH] Added try/catch handling around VideoCapture --- src/videobuffer.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/videobuffer.cpp b/src/videobuffer.cpp index 6e694fd..8f9799a 100644 --- a/src/videobuffer.cpp +++ b/src/videobuffer.cpp @@ -106,8 +106,21 @@ void imageCollectionThread(void* arg) { dispatcher->mMutex.lock(); - bool hasImage = cap.read(frame); - dispatcher->setLatestFrame(&frame); + bool hasImage = false; + try + { + hasImage = cap.read(frame); + dispatcher->setLatestFrame(&frame); + } + catch (int e) + { + // Error occured while trying to gather image. Retry, don't exit. + std::cerr << "Exception happened " << e << std::endl; + } + // Double check the image to make sure it's valid. + if (frame.cols == 0 || frame.rows == 0) + hasImage = false; + dispatcher->mMutex.unlock(); if (hasImage == false)