Unhanded Exception during list push_back C++ -


i implementing 2 lists of class objects in project. originally, had 1 vector container 1 group of class objects , list other have converted vector implementation list.

everything worked fine vector , list implementation, however, when converted vector list (and changed subsequent code) unhanded exception when try push_back (or insert) object list.

unhandled exception @ 0x004184e2 in pn_test.exe: 0xc0000005: access violation reading location 0x00000004.

this results following:

in .hpp file:

    class ssmcsection {          public:             data8* sectstartaddress;             data32 sectsize;     };  std::list<ssmcsection> sections; 

in .cpp file:

ssmcsection sec0; sec0.sectstartaddress = memheadaddress; sec0.sectsize = 0; sections.push_back(sec0); //<- dies in call 

exception in list library:

void _insert(const_iterator _where, const _ty& _val) {   // insert _val @ _where #if _iterator_debug_level == 2     if (_where._getcont() != this)     _debug_error("list insert iterator outside range"); #endif /* _iterator_debug_level == 2 */      _nodeptr _pnode = _where._mynode(); _nodeptr _newnode =         this->_buynode(_pnode, this->_prevnode(_pnode), _val); // <- exception occurs in list library _incsize(1); this->_prevnode(_pnode) = _newnode; this->_nextnode(this->_prevnode(_newnode)) = _newnode; } 

edit:: showing before , after

my class definition before:

class smmc {      public:         ...      class ssmcsection {          public:             data8* sectstartaddress;             data32 sectsize;     };      class smmcallocdata {          public:         bool allocated;         data8* start;         data8* end;         data32 sectionnum;     };      private:         std::list<smmcallocdata> memmap;          std::vector<ssmcsection> sections; }; 

my class implementation before:

ssmcsection sec0; sec0.sectstartaddress = memheadaddress; sec0.sectsize = 0; sections.push_back(sec0);  ...  smmcallocdata newsec; newsec.allocated = true; newsec.start = memheadaddress; newsec.end = memheadaddress + spacerequested; newsec.sectionnum = sections.size()-1; memmap.push_back(newsec); 

all of worked fine. below shows changes:

my class definition after:

class smmc {      public:         ...      class ssmcsection {          public:             data8* sectstartaddress;             data32 sectsize;     };      class smmcallocdata {          public:         bool allocated;         data8* start;         data8* end;         data32 sectionnum;     };      private:     std::list<smmcallocdata> memmap;          std::list<ssmcsection> sections; //changed vector list }; 

my class implementation after:

ssmcsection sec0; sec0.sectstartaddress = memheadaddress; sec0.sectsize = 0; sections.push_back(sec0);  ...  smmcallocdata newsec; newsec.allocated = true; newsec.start = memheadaddress; newsec.end = memheadaddress + spacerequested; newsec.sectionnum = sections.size()-1; memmap.push_back(newsec); 

this fails @ "sections.push_back(sec0);". exact same thing doing smmcallocdata list...!!??

i dont understand why worked other list container, not one... examples list show usage identical this. using ms vs2010.

any thought?? thanks!

hmmm... works now!?

i reverted original implementation (using vector , list) , confirmed worked. commented out vector code , replaced list (routinely running make sure still working through out transition) until replaced vector code....

now works supposed to. make sure not going crazy, diff'ed "broken code" original post working code, , same!

either odd ms vs issue or missing something.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -