iterator not decrementable について
Posted: 2014年8月30日(土) 01:17
DXライブラリなどを利用して,
指定された多角形の座標内にマウスポインタが存在するかを知るための関数を作っています.
デバック開始直後は誤作動なく進むのですが,
いざこの関数を利用しようという操作をすると,
Debug Assertion Failed!
~
Expression: vector iterator not decrementable
とエラーが表示されてしまいます.
ブレークポイントを使って,どこがおかしいのか調べてみると,
vector< vector<int> >::const_iterator it_pre_end = --it_end ;
の部分でエラーが起きていることがわかりました.
しかし,どうしてこの部分でエラーが起きてしまっているのかがわかりません.
このエラーの時に,よくやってしまいがちなミスなどがあれば教えていただきたいです.
指定された多角形の座標内にマウスポインタが存在するかを知るための関数を作っています.
デバック開始直後は誤作動なく進むのですが,
いざこの関数を利用しようという操作をすると,
Debug Assertion Failed!
~
Expression: vector iterator not decrementable
とエラーが表示されてしまいます.
ブレークポイントを使って,どこがおかしいのか調べてみると,
vector< vector<int> >::const_iterator it_pre_end = --it_end ;
の部分でエラーが起きていることがわかりました.
しかし,どうしてこの部分でエラーが起きてしまっているのかがわかりません.
このエラーの時に,よくやってしまいがちなミスなどがあれば教えていただきたいです.
#define _USE_MATH_DEFINES
#include <vector>
#include <algorithm>
#include <math.h>
#include <iterator>
bool Shop::MousePointer(const vector< vector<int> > Map)
{
//マウスの座標を取得
GetMouseInputLog(&Button, &ClickX, &ClickY, TRUE);
//ボックス内にマウス座標が存在するか
//多角形の頂点から2つの点を選び,それらと点Pの3つ点からなる角度を足していき,360度,-360度ならボックス内.
//0度ならボックス外.
vector< vector<int> >::const_iterator it_v = Map.begin();
vector< vector<int> >::const_iterator it_end = Map.end();
vector< vector<int> >::const_iterator it_pre_end = --it_end ;
double sum = 0;
while (it_v != it_pre_end){
vector< vector<int> >::const_iterator map;
map = it_v;
sum += Angle((*map)[0], (*map)[1], (*(map+1))[0], (*(map+1))[1], ClickX, ClickY);
++it_v;
}
sum += Angle((*it_pre_end)[0], (*it_pre_end)[1], (*(Map.begin()))[0], (*(Map.begin()))[1], ClickX, ClickY);
if (358 < sum < 362 || 179< sum < 181){
return true;
}
else{
return false;
}
}
//角APB
double Shop::Angle(int xA, int yA, int xB, int yB, int xP, int yP){
double angle;
int tmp_xA, tmp_yA, tmp_xB, tmp_yB;
int cos, sin;
tmp_xA = xA - xP;//ベクトルOA
tmp_yA = yA - yP;
tmp_xB = xB - xP;//ベクトルOB
tmp_yB = yB - yP;
cos = tmp_xA * tmp_xB + tmp_yA * tmp_yB;
sin = tmp_xA * tmp_yB - tmp_yA * tmp_xB;
angle = atan2(sin, cos);
return (angle * 180.0) / (M_PI);
}
Shop::Shop(){
~
vector<vector<int>> left_box = { { 481, 576 }, { 497, 567 }, { 528, 567 }, { 528, 584 }, { 497, 584 } };
vector<vector<int>> right_box = { { 550, 567 }, { 578, 567 }, { 528, 576 }, { 578, 584 }, { 550, 584 } };
vector<vector<int>> buy_box = { { 668, 401 }, { 731, 401 }, { 738, 405 }, { 738, 451 }, { 731, 458 }, { 668, 458 }, { 661, 451 }, { 661, 405 } };
vector<vector<int>> leave_box = { { 660, 502 }, { 738, 501 }, { 747, 507 }, { 747, 569 }, { 738, 577 }, { 660, 577 }, { 652, 569 }, { 652, 507 } };
}