trying to get my bullet's to hit my player, had a friend come over and he made a iterator thing out of my bullet's fire function and now when ever I press the fire button for my player my game crashes and the error message is "Unhandled exception at 0x77a215de in GL_Template_d.exe: 0xC0000005: Access violation reading location 0xcdcdce01."
A: You're not destroying the bullet if it's not on the screen. You're destroying it if it's alive (whatever that means for a bullet.)
B. m_plBullets.erase(M_BulletItr) can return m_plBullets.end() in which case the for loop attempts to increment it before comparing it to end, resulting in undefined behavior.
Should look something like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
auto i = m_plBullets.begin() ;
while ( i != m_plBullets.end() )
if ( (*i)->isAlive() )
--m_iBulletAmount ; // why keep this variable? Just use m_plBullets.size()
delete *i ;
i = m_plBullets.erase(i) ;