Skip to main content
deleted 1 character in body
Source Link
CobaltHex
  • 2.3k
  • 12
  • 18

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

Example:

for (auto&auto entity : toDeleteEntities)
    RemoveEntity(entity);
toDeleteEntities.clear();

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

Example:

for (auto& entity : toDeleteEntities)
    RemoveEntity(entity);
toDeleteEntities.clear();

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

Example:

for (auto entity : toDeleteEntities)
    RemoveEntity(entity);
toDeleteEntities.clear();

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards

added 121 characters in body
Source Link
CobaltHex
  • 2.3k
  • 12
  • 18

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

Example:

for (auto& entity : toDeleteEntities)
    RemoveEntity(entity);
toDeleteEntities.clear();

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

Example:

for (auto& entity : toDeleteEntities)
    RemoveEntity(entity);
toDeleteEntities.clear();

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards

Source Link
CobaltHex
  • 2.3k
  • 12
  • 18

Looks like the issue is your toDeleteEnemies loop. As you remove entries, your list will shrink, but your counter is still going up. So when you get past half way, you're now out of bounds of the array. You can also optimize this either way by just clearing the list after going through each entry, as you are only acting on each item once

A few other suggestions, Use smart pointers, to avoid having to manually call delete (and end up with other potential memory bugs).

And, avoid hard coded numbers (magic numbers). Define them as constants somewhere and refer to them by name

One other note, if you are adding an item to the toDelete list, you probably don't need to call its update method afterwards