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 );