read/write access violation c++ using libfreenect2

334 Views Asked by At

I'm a newbe to C++ and started fooling around with my Kinect V2 and libfreenect2. The building of the library worked fine for me, I guess. But when I try to use it in my code I get some weird exceptions.

Freenect2 freenect2;
std::string serial="";
Freenect2Device *dev = 0;

freenect2.enumerateDevices();
serial = freenect2.getDefaultDeviceSerialNumber();
dev = freenect2.openDevice(serial);

Everytime I run this code, it fails at getting the serial number [serial = freenect2.getDefaultDeviceSerialNumber();] with:

"Unhandled exception thrown: read access violation.

_Pnext was 0xFFFFFFFFFFFFFFFF."

In case I'm using

Freenect2 freenect2;
Freenect2Device *dev = 0;
SyncMultiFrameListener listener(Frame::Color);
FrameMap frames;

freenect2.enumerateDevices();
dev = freenect2.openDefaultDevice();
dev->setColorFrameListener(&listener);
dev->start();

listener.waitForNewFrame(frames)

instead, it fails while waiting for a new frame [listener.waitForNewFrame(frames)] with following exception thrown:

" Exception thrown at 0x000000018026D0C2 (ig75icd64.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation writing location 0x000000002BA0D700. "

So, what am I doing wrong and how can I do it better?

Thanks for your advice.

Edit: shortened the code...

1

There are 1 best solutions below

0
On

I was facing the same problem on Debug mode but it worked on Release.

After some hours researching, I've managed to solve the problem through a compilation flag on the libfreenect2 project (on debug setting).

The freenect2 project was marked as Multi-threaded DLL (/MD) and if you change it to Multi-threaded Debug DLL (/MDd) it should work.

In VS2015 you can access this property on:

Project Properties -> C/C++ -> Code Generation ->Runtime Library