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

  • Home
  • SEARCH
  • 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 6078279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:48:54+00:00 2026-05-23T10:48:54+00:00

The problem was a stupid error from another class accessing the vector and deleting

  • 0

The problem was a stupid error from another class accessing the vector and deleting iterators. Nothing to do with the code below. Sorry to waste your time.

I must be missing something elementary.
I’ve got a function which creates an object, manipulates it’s data and then pushes it into a vector.
The moment the function exits, the program crashes with a SIGSEV, and I’m left staring at (Kdevelop gcc 4.5 gdb) :

   /**
   *  The dtor only erases the elements, and note that if the
   *  elements themselves are pointers, the pointed-to memory is
   *  not touched in any way.  Managing the pointer is the user's
   *  responsibility.
   */
  ~vector()
  { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
          _M_get_Tp_allocator()); }

I am not storing pointers, I’m trying to store instantiated objects.

void Init::initIndividual(int ID, int gen)
{
  Individual temp_person = Individual(ID,gen);
  int inst_size = getRandom<int>(1,max_inst_size);
  for (int k=0;k<inst_size;k++)
  {
    retry:
    // (1) randomly choose a body part
    int body_num = getRandom<int>(1,20);
    body_part temp_part = get_body_part(body_num);
    // NOTE: We need to make sure that the body part is unique!
    std::vector<Instruction> already_existing = temp_person.get_instructions();
    if (already_existing.size() > 0)
    {
      for (int a=0; a< already_existing.size();a++)
      {
       std::string name = already_existing[a].get_body_part();
       if ( name.compare(temp_part.name) == 0 )
       { //if body part already exists in the list, retry!
         goto retry;
       }
      }
    }    
    // (2) Create a new Instruction for this body part
    Instruction temp_inst = Instruction(temp_part.name,temp_part.max_angle,temp_part.min_angle);
    // (3) Randomly pick a number of body parameters to use
    int paramsize = getRandom<int>(1,max_params_size);
    // (4) Randomly choose time and degree trajectory parameters for this body part and append!
    for (int x=0;x < paramsize; x++)
    {
     float time = 0.0f;
     int choice = 0;
     // (4.a) If begin of body parameters
     if (x==0)
     {
   //if always start at time = 0
   if (static_time_init)
   {
     time = 0.0f;
   }
   //if randomly choose the init time
   else if (!static_time_init)
   {
     time = getRandom<float>(0.0f,(float)(time_constrain-1));
   }
     }
     // (4.b) if not @ start of params
     else if(x!=0)
     {
       redo:  
       float previous_time = temp_inst.parameters.back().time; //get previous time
       double incrementor = getRandom<double>(0.1,1.0); //increment time by min 0.1 max 1.0
       time = previous_time + (float)incrementor;
       if (time > time_constrain) //if current time is more than time constrain, redo
       { 
        goto redo;
       }
     }
     // (5) Randomly pick a degree to move to (within body part constrains)
     float degree = getRandom<float>(temp_inst.get_min_angle(),temp_inst.get_max_angle());
     Parameter foo = Parameter(time,degree);
     temp_inst.add_parameter(Parameter(time,degree));
   }
  temp_person.add_Instruction(temp_inst);
  }
  temp_person.endtime = time_constrain;
 }

That is the entire function.

 std::vector<Individual> population;

Doesn’t the push_back function copy the object when pushing it back ?
Is the destructor invoked because push_back is trying to destroy temp_person ?
I have not defined a copy operator in class Individual.
I have run into this problem before and never figured it out.
Does this happen because at the end of the function temp_person is out of scope ?
Thank you !

Edit: Class Individual

class Individual 
{
   friend class Population;
   friend class Crossover;
   friend class Init;
 private:
   std::string xml_file;
   char *arg4;
 protected:
   bool saved, mutated, dead;
   unsigned int UID, generation;
   int executions;
   std::vector<Instruction> instructions;
   int father_UID, mother_UID;
   double eta,endtime;
 public:
   int uniform;
   float fitness;
   pthread_mutex_t thread_mutex;
   //Some other functions irrelevant

Please note, that the vector of instructions has another vector of structs.

class Instruction 
{
  friend class Crossover;
 private:  
  unsigned int param_size;
  float max_angle, min_angle;
  bool micro_mutated;
 public:
  std::string body_part;
  std::vector<Parameter> parameters;
  //other stuff

class Parameter
{
  public:
   float time;
   float degree;
   Parameter(float t,float d);
};

Nothing crazy here.

Could this be a problem of a shallow copy obtained by the population.push_back ?

  • 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-05-23T10:48:54+00:00Added an answer on May 23, 2026 at 10:48 am

    The problem was a stupid error from another class accessing the vector and deleting iterators. Nothing to do with the code above. Sorry to waste your time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

stupid problem. I get those from a client connecting to a server. Sadly, the
PROBLEM SOLVED! STUPID TYPO IN MY CODE! That's my method of my UIScrollView delegate:
This is probably really stupid but i can't find the problem with my code.
Sorry for asking a stupid question but I have a problem that makes me
I have a problem with linking and gcc, probably resulting from a stupid mistake
well i have most probably an extremly stupid problem but could not figure it
I have a simple stupid question. Here's the problem, for years, my company has
Well, maybe it is a stupid question, but I cannot resolve this problem. In
Problem: I have an address field from an Access database which has been converted
I have two classes which both extend from SQL class like this: class SQL

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.