私は、次のコードからプログラムのクラッシュを取得しています:C++マップベクトル参照エラー
// declaration in header:
std::vector<Animation> mAnimations; // animation objects
std::map<std::string, Animation*> mBoneAnimations; // map strings to animation objects from "mAnimations"
// source code in source file:
this->mAnimations.push_back(Animation());
this->mBoneAnimations[bone_name] = &this->mAnimations.back();
// ...
// at different points, we modify the LAST element in animation
this->mAnimations.back().addTranslation(Vector3(...));
// this is where the problem occurs later on in the program:
Animation test = *(this->mBoneAnimations.at("Body")); // CRASH
このコードは、最後の行にクラッシュします。私はこの問題が、このデータ構造を設定した方法によって引き起こされたことを80%確信しています。私の推測では、 "back()"を使ってベクター内の最後のオブジェクトへの参照を取得している可能性があります。私はそれに変更しようとしました:
this->mBoneAnimations[bone_name] = &this->mAnimations[this->mAnimations.size() - 1];
しかし、これも役に立たなかった。問題はこのクラッシュを引き起こす原因であり、具体的にはどのように修正できますか?
編集:私はそこに "ボディ"オブジェクトがあると確信しています。このクラッシュはメモリエラーです。
"Body"キーがマップに存在していることを確認してください。アニメーションはコピー可能ですか?ところで、 "Body"は "body"と同じではありません(大文字と小文字が区別されます)。 –
@HumamHelfawiは、ありがとうございます。残念ながら私は確信しています。 – Jas