PDA

View Full Version : Program crashes, where I did wrong?



yan_zhao_ep
June 18, 2014, 04:25:34
Hi all,

I am new to the device and the SDK. I just want to write some simple code to list the names of the devices connected to my PC.

Here is my code:


// construct a new Grabber pointer
Grabber* pGrabber = new Grabber();

// Get a list of devices
Grabber::tVidCapDevListPtr pDevList = pGrabber->getAvailableVideoCaptureDevices();

// iterate through all devices
for(Grabber::tVidCapDevList::iterator pDev = pDevList->begin();
pDev != pDevList->end(); pDev++)
{
std::cout<<(*pDev).getBaseName()<<std::endl;
}


It crashes at


pDevList->begin()


I am not sure if I didn't use the smart_ptr properly or it's because of something else. Please advice. (BTW I only have one device connected on my PC at the moment.)


Thanks very much.


Regards,

YZ

Stefan Geissler
June 18, 2014, 07:54:31
Dear YZ

You did not nothing wrong. I guess, you simply did not call InitLibrary() before you do anything else



InitLibrary();
Grabber* pGrabber = new Grabber();

// Get a list of devices
Grabber::tVidCapDevListPtr pDevList = pGrabber->getAvailableVideoCaptureDevices();

// iterate through all devices
for(Grabber::tVidCapDevList::iterator pDev = pDevList->begin();
pDev != pDevList->end(); pDev++)
{
std::cout<<(*pDev).getBaseName()<<std::endl;
}


Please refer to http://www.imagingcontrol.com/en_US/support/documentation/class/meth_descreffunctions_InitLibrary.htm

yan_zhao_ep
June 18, 2014, 14:05:20
Thanks for the help Stefan, it works now.