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.
This commit is contained in:
Sam Bromley 2012-07-26 12:36:21 -02:30
parent 49b55a7245
commit 966a652142

View File

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