c++ - std::bad_alloc error with SFML -


i working on project sfml involves lot of menus lot of buttons, creating functions take minimal input , automatically create , format these buttons. had working splendidly when function called constructed buttons parameters, want simplify take strings, used construct buttons, stored in vector. when tried doing this, recieved error:

unhandled exception @ 0x76a7c41f in menu.exe: microsoft c++ exception: std::bad_alloc @ memory location 0x003cd0a0.. 

and pointed in dbgheap.c:

 (;;)     {         /* allocation          */ here>>> pvblk = _heap_alloc_dbg_impl(nsize, nblockuse, szfilename, nline, errno_tmp);          if (pvblk)         {             return pvblk;         }         if (nhflag == 0)         {             if (errno_tmp)             {                 *errno_tmp = enomem;             }             return pvblk;         }          /* call installed new handler */         if (!_callnewh(nsize))         {             if (errno_tmp)             {                 *errno_tmp = enomem;             }             return null;         }          /* new handler successful -- try allocate again */     } 

here code, , changed.

this function provides no errors:

void page::addleft(int n, ...) { va_list left; va_start(left, n); (int = 0; < n; i++) {     leftbuttons.push_back(va_arg(left, button));      //takes parameters of type "button", working custom class } va_end(left); } 

this function gives me unhandled exception: std::bad_alloc

void page::addleft(int n, ...) { va_list left; va_start(left, n); (int = 0; < n; i++) {     std::string s = va_arg(left, std::string);      //takes parameter of type "string" , uses in default constructor       //of button. default constructor button works.      leftbuttons.push_back(button(s)); } va_end(left); } 

i new sfml, don't think that's problem here. , appreciated.

va_arg doesn't work std::string. after first iteration of loop going reference unknown memory. 1 way make example work follows:

void page::addleft(int n, ...) { va_list left; va_start(left, n); (int = 0; < n; i++) {     std::string s = va_arg(left, const char *);      //takes parameter of type "string" , uses in default constructor       //of button. default constructor button works.      leftbuttons.push_back(button(s)); } va_end(left); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -