5

std::vectorは確かに素晴らしいですね。

ただし、要素を追加するためEXC_BAD_ACCESSに使用しています。push_back(私はかつて同様の問題を抱えていましたが、SOで調べて解決しました!悲しいことに、これは別の問題のようです。)

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

(Beatいくつかのデータを運ぶ単純な構造体のようなクラスです。)

 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いくつかの数字を処理して、各グループを画面上の適切な場所に配置します。)

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

そして、ここに問題があります:

 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);
 }

時々gdb私を連れて行きます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); }

その他の時間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(); }
4

1 に答える 1

4

BackgroundGroupsHandler問題は、呼び出しaddBeatている がNULL無効なポインタである可能性が最も高いです。std::vectorを使用しているため、コードに問題が表示されます。groupsこれは、が無効であるためBackgroundGroupsHandler無効になります。

于 2011-06-04T13:05:50.480 に答える