PDA

View Full Version : grabber.openDev() problem



tsyba.y.a
October 25, 2017, 07:16:16
Hello! I'm using MSVS 2015. When I try to open device I got Exception thrown:

///////////////////////////////////////////////////////////
Exception thrown at 0x00007FFD59FC8633 (TIS_UDSHL11d_x64.dll) in IC_WriteSampleVideo.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

If there is a handler for this exception, the program may be safely continued.
//////////////////////////////////////////////////////////

Code of function:
bool select_openCam(std::vector<DShowLib::Grabber>& grabber)
{
// Function for choosing which cameras to open and use for writing videos
//

grabber.resize(1); // for getting availabeVideoCaptureDevices;

DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList = grabber[0].getAvailableVideoCaptureDevices();
if (pVidCapDevList->size() == 0)
{
std::cout << "No available Devices";
return false;
}
else
{
std::cout << "Available Devices:\n";
unsigned int i = 0;
for (DShowLib::Grabber::tVidCapDevList::const_iterator it=pVidCapDevList->begin(); it!=pVidCapDevList->end(); ++it)
std::cout << i++ <<". " << it->getBaseName() << std::endl;

// Choose number of cameras
unsigned int ncam = 0;
std::cout << "\nHow many cameras do you want to use for recording?";
std::cout << "\nNcam = ";
while (!(std::cin >> ncam) || ncam<0 || ncam > pVidCapDevList->size()) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Try again: Ncam = ";
}
grabber.resize(ncam);

if (ncam == 0)
return false;

// Open all cameras
else if (ncam == pVidCapDevList->size())
{
/*for (unsigned int i = 0; i < ncam; ++i)
if (!grabber[i].openDev(pVidCapDevList->at(i)))
{
std::cerr << "\nError to open " << pVidCapDevList->at(i).getBaseName();
std::cerr << "\nError:" << grabber[i].getLastError().toString();
return false;
}*/

for (auto i = std::make_pair(grabber.begin(), pVidCapDevList->begin()); //std::pair<std::vector<DShowLib::Grabber>::iterator, DShowLib::Grabber::tVidCapDevList::const_iterator> i(grabber.begin(), pVidCapDevList->begin())
i.first!=grabber.end();
++i.first, ++i.second)
if ( !i.first->openDev(i.second->getBaseName()) )
{

std::cerr << "\nError to open " << i.second->getBaseName();
std::cerr << "\nError:" << i.first->getLastError().toString();
return false;
}
}

// Open only selected cameras
else
{
std::vector<int> icam(ncam);
bool bRepeat;
int i = 0;
std::cout << "\nChoose cameras (Write index of camera and press enter):\n";
while (i != ncam)
{
bRepeat = false;
while (!(std::cin >> icam[i]) || icam[i]<0 || icam[i] >= pVidCapDevList->size()) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Try again: ";
}

//Check for repeted index of camera
for (int j = 0; j<i; ++j)
if (icam[j] == icam[i])
{
std::cout << "You have already chose that camera. Try again:\n";
bRepeat = true;
}
if (!bRepeat)
++i;
}

// Open grabbers
for (unsigned int i = 0; i<ncam; ++i)
if (!grabber[i].openDev(pVidCapDevList->at(icam[i])))
{
std::cerr << "\nError to open " << pVidCapDevList->at(i).getBaseName();
std::cerr << "\nError:" << grabber[i].getLastError().toString();
return false;
}

}
}

return true;
}

Stefan Geissler
October 25, 2017, 09:43:45
The error can happen, if there are cameras in the system with bad drivers. Are there other cameras in your system?
Which output do you receive, if you change the open code at



// Open grabbers
for (unsigned int i = 0; i<ncam; ++i)
{
std::cerr << "\try to open " << pVidCapDevList->at(i).getBaseName();
if (!grabber[i].openDev(pVidCapDevList->at(icam[i])))
{
std::cerr << "\nError to open " << pVidCapDevList->at(i).getBaseName();
std::cerr << "\nError:" << grabber[i].getLastError().toString();
return false;
}
}

tsyba.y.a
October 26, 2017, 03:56:12
The main notice, that that exception occurs periodically and in different adresses. Sometime it runs normal, sometimes not. Even with your code situation the same.

But today I found the special feature. If I substitute std::vector<DShowLib::Grabber>& for DShowLib::Grabber* (and allocate memory of it), I don't have any exceptions.

I know that it sounds strange. Is it possible that problem with a placing grabbers to container?

tsyba.y.a
October 26, 2017, 07:08:43
I found a problem. The first time I resize grabber to for getting availabe Video Capture Devices

grabber.resize(1); // for getting availabeVideoCaptureDevices;
After that I resize it to number of cameras

grabber.resize(ncam);
And when I try to open device I receive exception, but If you substitute

grabber.resize(1); // for getting availabeVideoCaptureDevices;

DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList = grabber[0].getAvailableVideoCaptureDevices();
for

DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList;
{
DShowLib::Grabber grabber_temp;
pVidCapDevList = grabber_temp.getAvailableVideoCaptureDevices();
}
you don't receive any exceptions.

Stefan Geissler
October 26, 2017, 09:14:10
Hi

It is nice to see, what you are doing. However, I made a suggestion and wanted to know its output. Unfortunately you did not see that part, I got not output.

tsyba.y.a
October 26, 2017, 09:39:04
Sorry Stefan,

I should have written output to you.
I changed code as you said:

for (unsigned int i = 0; i<ncam; ++i)
{
std::cerr << "\try to open " << pVidCapDevList->at(i).getBaseName();
if (!grabber[i].openDev(pVidCapDevList->at(icam[i])))
{
std::cerr << "\nError to open " << pVidCapDevList->at(i).getBaseName();
std::cerr << "\nError:" << grabber[i].getLastError().toString();
return false;
}
}

And I tried to run program 10 times.
There are outputs:

1. Exception thrown at 0x00007FF9402D8633 (TIS_UDSHL11d_x64.dll) in IC_CreateVideo.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

2. No exceptions. Everything opened successfully.

3. Exception thrown at 0x00007FF9402D8633 (TIS_UDSHL11d_x64.dll) in IC_CreateVideo.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

4. Exception thrown at 0x00007FF9403D8633 (TIS_UDSHL11d_x64.dll) in IC_CreateVideo.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

5. Exception thrown at 0x00007FF9402D8633 (TIS_UDSHL11d_x64.dll) in IC_CreateVideo.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

6. No exceptions. Everything opened successfully.

7. No exceptions. Everything opened successfully.

8. No exceptions. Everything opened successfully.

9. No exceptions. Everything opened successfully.

10. Exception thrown at 0x00007FF9403D8633 (TIS_UDSHL11d_x64.dll) in IC_CreateVideo.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

Stefan Geissler
October 26, 2017, 13:22:32
Which cameras do you use?

tsyba.y.a
October 27, 2017, 03:31:53
DMK 33GP2000e