im using vectors and i get acsses violations which i think causes GDK to crush at some points
here is parts of code obviusly i wont publish the entire code
but if you see something wrong pls help cause im kinda lost
creeps (ai bots) update
void UpdateCreeps(void)
{
// Updating Creeps
for (int c =0; c < creeps.size(); c ++)
{
int temp = creeps[c].Update() ; // 1 reached end point , 2 died cause hp is lower or equal to 0
if (creeps[c].dead) // if a creep is dead
{
creeps.erase(creeps.begin() + c);
c--;
}
else if (temp == 1 && lives > 0) // if a creep reached end point one life decrease
{
lives --;
}
else if (temp == 2) // if a creep is dead by towers money increase
{
cash += creeps[c].cost;
}
}
}
bullets update
void UpdateBullets(void)
{
// Updating Bullets
for (int b1 = 0; b1 < blts.size(); b1 ++)
{
if (blts[b1].alive)
{
int col = blts[b1].Update();
if (col > 0)
{
for (int bj = 0; bj < creeps.size(); bj ++)
{
if (col == creeps[bj].id)
{
creeps[bj].hp -= blts[b1].dmg;
}
}
}
}
}
// second Checking if bullets are dead
for (int b = 0; b < blts.size() ; b++)
{
if (!blts[b].alive)
{
if (dbIsObject(blts[b].id) == 1)
{
SC_RemoveObject(blts[b].id);
dbDeleteObject(blts[b].id);
blts.erase(blts.begin() + b);
b--;
}
}
}
}
turrets Update
// Updating Turrets
for (int t1 = 0; t1 < PlayerT.size(); t1++)
{
PlayerT[t1].Update();
if (PlayerT[t1].locked > 0)
{
if (GetDistance(PlayerT[t1].id,PlayerT[t1].locked) > PlayerT[t1].range)
{
PlayerT[t1].locked = 0;
}
for (int tj = 0; tj < creeps.size(); tj ++)
{
// if a tower is locked on a creep
if (PlayerT[t1].locked == creeps[tj].id)
{
// if the creep is in range
if (GetDistance(PlayerT[t1].id,PlayerT[t1].locked) < PlayerT[t1].range)
{
// if tower shooting timer achived
if (PlayerT[t1].sT.Update())
{
if (dbIsObject(PlayerT[t1].locked) == 1)
{
blts.push_back(Bullet()); // pushing back a new bullet into bullet vector
// adding all bullet data and position
blts.back().Add(PlayerT[t1].dmg,PlayerT[t1].range,PlayerT[t1].colRange,PlayerT[t1].shootId,PlayerT[t1].bsX,PlayerT[t1].bsY,dbObjectPositionX(PlayerT[t1].id),dbObjectPositionY(PlayerT[t1].id),dbObjectPositionZ(PlayerT[t1].id),PlayerT[t1].locked);
}
}
}
// if the locked creep is dead releasing lock to enable the tower to lockon another creep
if (creeps[tj].dead)
{
PlayerT[t1].locked = 0;
}
}
}
}
// finding a new creep to lock on
for (int tj1 = 0; tj1 < creeps.size(); tj1 ++)
{
if (creeps[tj1].started)
{
if (GetDistance(PlayerT[t1].id,creeps[tj1].id) < PlayerT[t1].range && PlayerT[t1].locked == 0)
{
PlayerT[t1].locked = creeps[tj1].id;
}
}
}
}
}
and in game loop
do
{
UpdateHearts(); // Updating Hearts
UpdateGreenArrow(); // Updating Green Arrow
if (gameStarted)
{
if (creeps.size() == 0)
{
startWave = true;
}
if (startWave)
{
StartWave();
startWave = false;
}
// first checking to see if the player have lives left
if (lives <= 0) // game over
{
break;
}
MMX = dbMouseX(); // Storing Mouse X
MMY = dbMouseY(); // Storing Mouse Y
CameraMovement(); // Camera Movement
for (int j = 0; j < PlayerT.size(); j ++)
{
if (towerSelect == PlayerT[j].id)
{
dbHideObject(PlayerT[j].radiusId);
dbHideObject(PlayerT[j].levelId);
}
}
MouseClicks(); // Mouse Controls
for (int j = 0; j < PlayerT.size(); j ++)
{
if (towerSelect == PlayerT[j].id)
{
dbShowObject(PlayerT[j].radiusId);
dbShowObject(PlayerT[j].levelId);
}
}
UpdateCreeps(); // Updating Creeps
UpdateTurrets(); // Updating Turrets
UpdateBullets(); // Updating Bullets
//dbText(0,0,convertInt(dbScreenFPS())); // shows Screen Frame Per seconds
dbText(0,20,convertInt(cash)); // printing amount of case
//dbText(0,40,convertInt(lives)); // printing lives not needed since the hearts addition
dbText(0,60,convertInt(GetFreeObject()));
// Update the screen
//dbSetTextSize(48);
//dbCenterText(dbScreenWidth()/2,dbScreenHeight()/8,convertInt(waveNumber));
//dbSetTextSize(10);
}
else
{
StartCounter();
}
dbSync(0,0);
}