I've run this through the debugger and found the problem has to be something to do with the iterator. If anyone could point out why it crashes it would be appreciated.
Here's the portion of the code that's causing the problem:
struct bullet {
int obj;
int life;
};
// Baddy bullet list stuff
list<bullet*> baddy_bullets;
list<bullet*>::iterator bit;
bullet* temp_bullet;
void ADD_BADDY_BULLET(int orig)
{
temp_bullet=new bullet;
int c=200; // start bullet search from here
while (dbObjectExist(c)) c++;
temp_bullet->obj=c; temp_bullet->life=120;
dbCloneObject(c,bullet_obj);
dbPositionObject(c,dbObjectPositionX(orig),dbObjectPositionY(orig)+20,dbObjectPositionZ(orig));
dbSetObjectToObjectOrientation(c,orig);
// baddy bullets to group 4
SC_SetupObject(c,4,2);
baddy_bullets.push_back(temp_bullet);
}
void DO_BADDY_BULLETS()
{
if (baddy_bullets.size()!=0)
{
bit=baddy_bullets.begin();
while ( bit!=baddy_bullets.end() || baddy_bullets.size()!=0)
{
temp_bullet=*bit;
temp_bullet->life--;
if (temp_bullet->life!=0)
{
// check collision on bullet
dbMoveObject(temp_bullet->obj,15);
SC_UpdateObject(temp_bullet->obj);
// Has it hit the map scenary?
if (SC_GroupCollision(temp_bullet->obj,1))
{
dbDeleteObject(temp_bullet->obj);
delete temp_bullet;
bit=baddy_bullets.erase(bit);
}
else if (SC_GroupCollision(temp_bullet->obj,2))
{
// Have we hit the player?
dbDeleteObject(temp_bullet->obj);
delete temp_bullet;
bit=baddy_bullets.erase(bit);
}
else
{
bit++;
}
}
else
{
// life has reached 0 so kill the bullet
dbDeleteObject(temp_bullet->obj);
delete temp_bullet;
bit=baddy_bullets.erase(bit);
}
//if (baddy_bullets.size()==0) break;
} // END OF WHILE
}
}
Something in the DO_BADDY_BULLETS() function (probably the iterator) causes a fatal error...
Thanks in advance...
Warning! May contain Nuts!