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.
pull/1/head
Sam Bromley 12 years ago
parent 49b55a7245
commit 966a652142
  1. 7
      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 );

Loading…
Cancel
Save