Remove object from collisions as well when killing it

This commit is contained in:
zvon 2020-08-23 15:30:31 +02:00
parent 5f275081fe
commit aaaf668616

View File

@ -577,14 +577,21 @@ private:
void checkKilled() {
render_mutex.lock();
std::vector< int > killed;
std::vector< int > killed_collisions;
for ( long unsigned int i = 0; i < renderObjects.size(); i++ ) {
if ( renderObjects[i]->getKilled() )
killed.push_back( i );
if ( i < collisionObjects.size() && collisionObjects[i]->getKilled() )
killed_collisions.push_back( i );
}
std::reverse( killed.begin(), killed.end() );
std::reverse( killed_collisions.begin(), killed_collisions.end() );
for ( auto &index : killed ) {
renderObjects.erase( renderObjects.begin() + index );
}
for ( auto &index : killed_collisions ) {
collisionObjects.erase( collisionObjects.begin() + index );
}
render_mutex.unlock();
}