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 5979677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:41:36+00:00 2026-05-22T21:41:36+00:00

std::vector sure is great, hey? I’m getting an EXC_BAD_ACCESS in using push_back to add

  • 0

std::vector sure is great, hey?

I’m getting an EXC_BAD_ACCESS in using push_back to add an element, though. (I had a similar problem once, looked it up on SO, solved! Sadly, this appears to be a different issue.)

 class BackgroundGroupsHandler {
 public:
     void addBeat(Beat *b);
     vector<beat_display_group*> groups;
 };

(Beat is a simple struct-like class that carries some data around.)

 class beat_display_group {
 public:
     void draw_me(float, float, float, int);
     beat_display_group(int rhythmInt, int beatNumber);
     ~beat_display_group();
     int posy;
 private:
     int rhythmInt;
     int beatNumber;
     int posx;
 };

(beat_display_group crunches some numbers to put each group in the right place on the screen.)

 class BackgroundGroupsHandler {
 public:
     void addBeat(Beat *b);
     vector<beat_display_group*> groups;
 };

And here’s the problem:

 void BackgroundGroupsHandler::addBeat(Beat *b) {
      beat_display_group *c = new beat_display_group(b->rhythmInt);

      // EXC_BAD_ACCCESS ON THIS LINE:
      groups.push_back(c);
 }

sometimes gdb takes me to stl_vector.h:

  // [23.2.4.2] capacity
  /**  Returns the number of elements in the %vector.  */
  size_type
  size() const
  { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }

and other times new_allocator.h:

  // _GLIBCXX_RESOLVE_LIB_DEFECTS
  // 402. wrong new expression in [some_] allocator::construct
  void 
  construct(pointer __p, const _Tp& __val) 
  { ::new(__p) _Tp(__val); }

  void 
  destroy(pointer __p) { __p->~_Tp(); }
  • 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-22T21:41:37+00:00Added an answer on May 22, 2026 at 9:41 pm

    The problem is most likely that the BackgroundGroupsHandler that you are calling addBeat on is NULL or otherwise an invalid pointer. The problem shows up in the std::vector code because you are using groups, which will be invalid due to the BackgroundGroupsHandler being invalid.

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

Sidebar

Related Questions

I had encountered a problem while using Loki::Singleton , Loki::SmartPtr , and std::vector under
I have a std::vector<int> , and I want to delete the n th element.
#include <vector> #include <memory> using namespace std; class A { public: A(): i(new int)
Suppose I have a class similar to the following: #include <vector> class element {
std::vector< boost::variant<std::string, int> > vec; std::string s1(abacus); int i1 = 42; vec.push_back(s1); vec.push_back(i1); std::cout
I am having a strange issue when using the erase() function on a std:vector.
I am not sure why this doesn't compile: std::vector< const Obj& > myVector; void
Consider the following: std::vector<int> vec(1); // vector has one element std::fill(vec.begin(), vec.begin(), 42); std::fill(vec.begin()+1,
I am not sure what's wrong with this code : std::vector<int> myVector(0); if (myVector.back()
I saw the following code used to delete one selected element from std::vector :

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.