Vector.erase(Iterator) causes bad memory access
Posted
by xon1c
on Stack Overflow
See other posts from Stack Overflow
or by xon1c
Published on 2010-05-31T13:43:57Z
Indexed on
2010/05/31
13:53 UTC
Read the original article
Hit count: 243
Hi,
I am trying to do a Z-Index reordering of videoObjects stored in a vector. The plan is to identify the videoObject which is going to be put on the first position of the vector, erase it and then insert it at the first position. Unfortunately the erase() function always causes bad memory access.
Here is my code:
testApp.h:
vector<videoObject> videoObjects;
vector<videoObject>::iterator itVid;
testApp.cpp:
// Get the videoObject which relates to the user event
for(itVid = videoObjects.begin(); itVid != videoObjects.end(); ++itVid){
if(videoObjects.at(itVid - videoObjects.begin()).isInside(ofPoint(tcur.getX(), tcur.getY()))){
videoObjects.erase(itVid);
}
}
This should be so simple but I just don't see where I'm taking the wrong turn.
Thx, xonic
© Stack Overflow or respective owner