elliotwoods / ofxKinectForWindows2

Implementation of Kinect For Windows v2 API (not using KinectCommonBridge)
163 stars 70 forks source link

Bug : Data::Body has no default constructor (e.g. tracked should always initialise to false) #44

Closed p4sI closed 9 years ago

p4sI commented 9 years ago

Hi,

just encountered that bodies[i].tracked == true after the init()-function in Body.cpp is executed. Even without a Kinect the state gets set to true. This happens after the line 47 is executed, where the bodies vector get resized from 0 to 6, see https://github.com/elliotwoods/ofxKinectForWindows2/blob/master/src/ofxKinectForWindows2/Source/Body.cpp#L47

I fixed it by adding

for (int i = 0; i < BODY_COUNT; ++i)
{
    auto & body = bodies[i];
    body.clear();
}

after line 47.

PS: I'm using the 0.8.4 branch, someone should check if it happens in the master one as well

elliotwoods commented 9 years ago

Hi @p4sI thanks for spotting this

the total issue here is that Data::Body does not have a default constructor (i.e. to set tracked to false, etc). Let me fix this one.

p4sI commented 9 years ago

Hi, okay this makes sense. I thought booleans are false by default and wondered why it gets set to true.

elliotwoods commented 9 years ago

bool, int, float, etc have no default values in C/C++ they simply default to whatever was in memory there beforehand therefore you should be careful always to initialise their values

elliotwoods commented 9 years ago

thanks for the spot!