まず第一に、英語が下手で申し訳ありません。皆さんが私を理解してくれることを願っています:) WinAPIゲームを書いていますが、クラスの動作が非常に奇妙です.ベクトルを使用したすべての操作でプログラムがクラッシュするため、.exeが機能しなくなったとWindowsが言います. しかし、これらの行をデバッグすると、例外が発生します。
これは私のクラスヘッダーがどのように見えるかです:
#ifndef FIGURE_H_INCLUDED
#define FIGURE_H_INCLUDED
#include <vector>
#include <Windows.h>
#include "Other.h"
using namespace std;
enum Figure_Type { I, J, L, O, S, T, Z };
class Figure
{
public:
/* CONSTRUCTORS */
Figure();
Figure(Figure_Type);
/* MOVEMENT */
bool Move(vector<Cell>&, Direction&);
void Drop(vector<Cell>&);
bool Rotate(vector<Cell>&);
/* OTHER */
void Draw(HDC&);
private:
/* METHODS */
void Generate();
void GenerateMasks();
void GenerateFigure();
Figure GetFigureCopy() const;
/* DATA */
Shift shift;
char mask[4][4];
vector<Cell> vCells;
Figure_Type type;
int rotation;
};
#endif
私のコンストラクターは Generate() メソッドを使用しています。コードは次のとおりです。
void Figure::GenerateFigure()
{
vCells.clear();
int defPosX = 4,
defPosY = 20;
Cell cell;
for(int y = 0; y < 4; y++)
{
for(int x = 0; x < 4; x++)
{
if(mask[y][x] == '0')
{
cell.x = defPosX + x + shift.dx;
cell.y = defPosY - y + shift.dy;
vCells.push_back(cell);
}
}
}
}
そして、vCells.clear() メソッドと (最初の行にコメントすると) vCells.push_back(cell) 行で例外が発生します。実際、ベクター/ベクター反復子を使用したすべての操作は、イテレーターをインクリメントしてもプログラムをクラッシュさせます。これらは最初のものであるため、コードはそれらの後に実行されなくなります。例外テキスト:
「Tetris_completely_new.exe の 0x5A4ACD2 (msvcp110d.dll) で未処理の例外: 0xC000041D: ユーザーのコールバック中に未処理の例外が発生しました。」
そして、これらの例外は、217 の「xutility」行でスローされます。私はそれをコメントしました:
....
// MEMBER FUNCTIONS FOR _Container_base12
inline void _Container_base12::_Orphan_all()
{ // orphan all iterators
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != 0)
{ // proxy allocated, drain it
_Lockit _Lock(_LOCK_DEBUG);
for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
*_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
**(*_Pnext)->_Myproxy = 0;** // <------------ THIS LINE
_Myproxy->_Myfirstiter = 0;
}
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
....
私のCell 構造体は次のようになります。
struct Cell
{
Cell() : x(1), y(1) { }
Cell(int _x, int _y): x(_x), y(_y) { }
void Draw(HDC&) const;
bool operator ==(const Cell& a) const { return (x == a.x && y == a.y); }
bool operator !=(const Cell& a) const { return !(*this == a); }
int x;
int y;
};
そしてFigure コンストラクター:
Figure::Figure()
{
srand(time(NULL));
vCells.clear();
type = Figure_Type(rand() % 7);
rotation = 0;
shift.dx = 0;
shift.dy = 0;
Generate();
}