Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:09:49+00:00 2026-06-10T06:09:49+00:00

is there anybody using BWAPI who gets access violation error when accessing the Unit

  • 0

is there anybody using BWAPI who gets access violation error when accessing the Unit objects of the current game?

i am certain that the error is not in my code.. anyway.. is there anything i can do to avoid access violation?

i am getting this error sometimes at line with the comment bellow.. this code bellow execute many times and only sometimes i get the error..

int Squad::getSize() {

    int no = 0;

    for (int i = 0; i < (int) agents.size(); i++) {

        BaseAgent* agent = agents.at(i);

        if (agent != NULL && agent->isAlive() && agent->getUnit() != NULL && !agent->getUnit()->isBeingConstructed()) // this line
            no++;
    }

    return no;
}

this is the code that I use to remove an BaseAgent from the vector.. analyze that and see if i can do it better:

void AgentManager::cleanup() {

    //Step 2. Do the cleanup.
    int cnt = 0;
    int oldSize = (int)agents.size();
    for (int i = 0; i < (int)agents.size(); i++) {

        if (!agents.at(i)->isAlive()) {

            delete agents.at(i);

            agents.erase(agents.begin() + i);
            cnt++;
            i--;
        }
    }

    int newSize = (int)agents.size();
}

the BaseAgent code is on this link

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:09:51+00:00Added an answer on June 10, 2026 at 6:09 am

    I would speculate that this line:

    BaseAgent* agent = agents.at(i);
    

    is returning some invalid pointer which is not set to 0.

    Looking at your cleanup code, it looks a bit complicated. I would suggest

    1. looping over the entire vector, deleting the dead elements and
      setting the pointers to 0.

    2. After the loop, use the erase-remove idiom to remove all NULL pointers from the vector.

    step 1

    for (unsigned int i = 0; i < agents.size(); ++i) {
        if (!agents.at(i)->isAlive()) {
           delete agents.at(i);
           agents.at(i) = 0;
    }
    

    step 2

    agents.erase(std::remove(agents.begin(), agents.end(), 0), agents.end()); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to create mysql triggers using Activerecord migrations ? Has anybody
Has anybody written a plugin for outlook web access? Are there any resources to
I was wondering whether anybody out there is actively using Rhapsody TestConductor ? Or
I was wondering if anybody out there is doing their software builds using something
Anybody out there using BGL for large production servers? How many node does your
I'm new to stackoverflow. My question ia about gpuocelet. Is there anybody using it?
Is there anybody who knows how to use PJSIP in iOS? What is the
Im just wondering if theres a recommended syntax validator out there anybody can recommend?
Does anybody out there know how to setup Eclipse with MinGW or Cygwin to
Does anybody know if there is a way to display the text value of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.