void updatebullets(){ bool deleteprev = false; for(curpoint=head;curpoint!=NULL;curpoint=curpoint->next){ //modify bullets // this next section can leave you with curpoint being // an invalid pointer after deletebullet() is called if (deleteprev){deletebullet(curpoint->prev);deleteprev = false; }// so when you get down to here and you check curpoint->next// the program will crash if ((x < -SCREEN_X/2) || (x > SCREEN_X/2) ||(y > SCREEN_Y/2) || (y < -SCREEN_Y/2)){if (curpoint->next != NULL) deleteprev = true;else deletebullet(curpoint); } }}// An alternative method would be something like thisvoid updatebullets(){ bullet * curpoint = head; while(curpoint) { if ((curpoint->x < -1/2) || (curpoint->x > 1/2) || (curpoint->y > 1/2) || (curpoint->y < -1/2)) { // a temp copy of curpoint''s next item bullet *temp = curpoint->next; deletebullet(curpoint); // after deleting curpoint set curpoint // to the next item. either a real node // or 0 curpoint = temp; } else curpoint = curpoint->next; }}