Code Review, issue with vectors and ofxBox2d

Thanks in advance for any help you can offer. I’m sure this will be an easy issue to resolve.

Mainly I think I am having an issue with vectors. I am working with gameover’s ofxOpenNI to sense the hands and then just draw a ofxBox2dRect at the center.

The following is my code:

  
  
void testApp::update(){  
...  
for(int i =0; i<recordHandTracker.getNumTrackedHands(); i++){  
            ofxTrackedHand * tracked = recordHandTracker.getHand(i);   
              
            if(tracked->isBeingTracked) {  
                  
                handRects.clear();  
                  
                //box2d stuff here  
                ofxBox2dRect hRect;  
                hRect.setPhysics(1.0,0.53,3.0);  
                hRect.setup(box2d.world, (tracked->projectPos.x * scaleFix),(tracked->projectPos.y * scaleFix), 30, 10, true);  
                handRects.push_back(hRect);  
                  
                  
            }  
        }  
...  
}  
  

Then in DRAW I do something similar

  
  
void testApp::draw(){  
...  
for(int i =0; i<recordHandTracker.getNumTrackedHands(); i++){  
        ofxTrackedHand * tracked = recordHandTracker.getHand(i);   
          
        handRects[i].draw();  
}  
...  
}  
  

I basically get a bunch of “program received signal:‘EXC_BAD_ACCESS’” messages as soon as a second hand is introduced.

Thanks for the help.

seems like you would want to do it like this

  
  
for(int i =0; i<handRects.size(); i++)  
{     
        handRects[i].draw();    
}    
  

Thanks for the response jvcleave.

When I run the program, it’s still pausing and throwing me thread errors (of the same kind mentioned earlier) when a second hand is detected. I’m thinking it has something to do with box2d.

I’m wondering if I need to be destroying bodies too?
I’ve attached the thread error locations, not sure if it helps.

![](http://forum.openframeworks.cc/uploads/default/2098/Screen Shot 2012-01-13 at 10.03.43 AM.png)