Coder Social home page Coder Social logo

Crashing ("Debug assertion failed! Expression: vector subscript out of range") when removing colony with population of 0. about antsimulator HOT 3 OPEN

johnbuffer avatar johnbuffer commented on September 20, 2024
Crashing ("Debug assertion failed! Expression: vector subscript out of range") when removing colony with population of 0.

from antsimulator.

Comments (3)

marcoperic avatar marcoperic commented on September 20, 2024

In simulation's update() function, I have a check at the very bottom (below checkForFights and updateColoniesStats) that checks to see if any colonies are extinct. It looks like this:
for (Colony& colony : colonies) { if (colony.eliminated) removeColony(colony.id); }

eliminated is a bool that is triggered when the ant population is equal to zero.

When debugging, I see that the error originates from removeColony(uint8_t colony_id) and occurs in the for loop with c.stopFightsWith(colony_id);`

From there, the next error takes place in the Colony class in the stopFightsWith function, inside of the for loop, at if(a.target) {
Where a.target seems to be the problem. Here is the call stack:

image

Note that the first four lines have line numbers that should match with yours. Everything below operator bool() Line 359 probably differs from your code.

from antsimulator.

marcoperic avatar marcoperic commented on September 20, 2024

My thoughts:
I don't think anything I added to your code managed to cause this problem.
I think the problem comes from trying to iterate over the Ants of a colony that no longer exists (was deleted because population was 0). Maybe there is a problem with Ant.target when the colony is extinct, when there are no ants, or when the colony no longer exists?

In any case, debugging keeps pointing to lines of code involving if (ants.target), even when I try to patch this bug.

Let me know if there is anything I can do to help!

Regards,
Marco

from antsimulator.

johnBuffer avatar johnBuffer commented on September 20, 2024

Hello,
Thank you for your detailed analysis, I will look into this

from antsimulator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.