I was feeling pretty happy with the following bit of code working:
if ( obj_1Q.size() > 0 )
{
obj_1Q.erase( std::remove_if(obj_1Q.begin(), obj_1Q.end(), std::mem_fun_ref(obj_1::isactive)), obj_1Q.end() );
std::for_each(obj_1Q.begin(), obj_1Q.end(), std::mem_fun_ref(obj_1::render));
}
This all works perfectly with instance containers. Trying to modify the code for a vector of pointers I ended up with these:
#1.
if ( bulletQ.size() > 0 )
{
vector<bullet*>::iterator j = std::remove_if( bulletQ.begin(), bulletQ.end(), std::mem_fun(&bullet::isactive) );
if( j!=bulletQ.end() ) //just in case
for( vector<bullet*>::iterator i = bulletQ.end(); i!=j; i-- )
{
free ( bulletQ.back() );
bulletQ.pop_back();
}
std::for_each( bulletQ.begin(), bulletQ.end(), std::mem_fun(&bullet::render) );
}
and,
#2.
if ( bulletQ.size() > 0 )
{
vector<bullet*>::iterator j = std::remove_if( bulletQ.begin(), bulletQ.end(), std::mem_fun(&bullet::isactive) );
if( j!=bulletQ.end() )
for( vector<bullet*>::iterator i = bulletQ.end(); i!=j; i-- )
{
free ( i );
bulletQ.pop_back();
}
std::for_each( bulletQ.begin(), bulletQ.end(), std::mem_fun(&bullet::render) );
}
Okay, before you guys start flaming me for using pointers, let me just state my problems:
a) #1 causes an access violation, so there's definitely something wrong with determining the bounds.
b) #2 causes the weird "User breakpoint called from code at 0x.." in NTDLL! ...(). I gather this is an issue with the heap being corrupted, probably due to some unwarranted freeing. Apparently this only happens under WIN32 debug environment, but my game crashes even when I'm just executing the exe.
Any ideas? I'm sensing I'm pretty close but can't spot the problem. Can you help? Thanks.