From 966a652142267aab31b58453adc568c694324f92 Mon Sep 17 00:00:00 2001 From: Sam Bromley Date: Thu, 26 Jul 2012 12:36:21 -0230 Subject: [PATCH] Fix crash when polling for non-existent Kinects. If no Kinects are present, crash can result from stepping beyond end of device list. Now we check to ensure this does not happen. --- modules/highgui/src/cap_openni.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/highgui/src/cap_openni.cpp b/modules/highgui/src/cap_openni.cpp index b440e0a02e..a95f2fd046 100644 --- a/modules/highgui/src/cap_openni.cpp +++ b/modules/highgui/src/cap_openni.cpp @@ -575,7 +575,12 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index ) // Chose device according to index xn::NodeInfoList::Iterator it = devicesList.Begin(); - for( int i = 0; i < index; ++i ) it++; + for( int i = 0; i < index && it!=devicesList.End(); ++i ) it++; + if ( it == devicesList.End() ) + { + std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Faile + return; + } xn::NodeInfo deviceNode = *it; status = context.CreateProductionTree( deviceNode, productionNode );