マップのセルを一つずつクラスにしてみました。
セルは10×10なので合計100マスです。
それを(擬似?)二次元配列を使ってコードを書いてみたらそのポインタ関係のAssertionエラー(BLOCK_TYPE_IS_VALID(pHead->nBlockUse))がでて、デバッグがとまってしまいます。
ブレークポイントを置いて調べたところ、deleteのところでエラーが起こっていると突き止めました。
しかし、それ以上のことが調べても分かりません。
解決方法をご教授ください。
-------------------cell.h
#ifndef CELL_H_
#define CELL_H_
class Cell{
public:
void SetAttr(int other){attr=other;}
void SetFlag();
int ShowAttr(){return attr;}
private:
int attr;//属性
int flag;
};
#endif
--------------------------------object.h
#ifndef OBJECT_H_
#define OBJECT_H_
#include "Cell.h"
#include "define.h"
Cell (*cell)[MAP_WIDTH]=new Cell [MAP_HEIGHT][MAP_WIDTH];
#endif
---------------------------------extern.h
#ifndef EXTERN_H_
#define EXTERN_H_
#include "Object.h"
#include "define.h"
extern Cell (*cell)[MAP_WIDTH];
#endif
---------------------------ExtraFunction.cpp
void SetCellAttr(Cell (*ocell)[MAP_WIDTH]){
for(int h=0;h<MAP_HEIGHT;h++){
for(int w=0;w<MAP_WIDTH;w++){
ocell[h][w].SetAttr(MapData[h][w]);//MapDataは10×10の二次元配列
}
}
}
------------------------------main.cpp
#include "DxLib.h"
#include "map.h"
#include "Extern.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
if( DxLib_Init() == -1 || ChangeWindowMode(true) == -1 || SetMouseDispFlag(true) == -1 || SetDrawScreen(DX_SCREEN_BACK)==-1) // DXライブラリ初期化処理
{
return -1; // エラーが起きたら直ちに終了
}
SetCellAttr(cell);
while(ProcessMessage()!=-1){
DrawMap();
}
// キー入力待ち
WaitKey() ;
for(int h=0;h<MAP_HEIGHT;h++)
delete [] cell[h];
delete [] cell;
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}
----------------------------------------map.h
void DrawMap(){// マップを描く
int i , j ;
for( i = 0 ; i < MAP_HEIGHT ; i ++ )
{
for( j = 0 ; j < MAP_WIDTH ; j ++ )
{
if( cell[ i ][ j ].ShowAttr() == 0 )
{
DrawBoxMap( j * MAP_SIZE, i * MAP_SIZE, j * MAP_SIZE + MAP_SIZE, i * MAP_SIZE + MAP_SIZE,GetColor( 255 , 0 , 0 ) , TRUE ) ;
}else{
DrawBoxMap( j * MAP_SIZE, i * MAP_SIZE, j * MAP_SIZE + MAP_SIZE, i * MAP_SIZE + MAP_SIZE,GetColor( 0 , 255 , 0 ) , TRUE ) ;
}
}
}
}
なお、main.cpp内の
for(int h=0;h<MAP_HEIGHT;h++)
delete [] cell[h];
のところで、h=1が入った周にdeleteしようとするとエラーであります。
また、あまりにも問題からかけ離れていると思われる部分は省略いたしました。