何故かアクセス違反が起きる

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
アバター
夢幻ノ月夜
記事: 143
登録日時: 9年前
住所: Stens;Gate世界線

何故かアクセス違反が起きる

#1

投稿記事 by 夢幻ノ月夜 » 8年前

なぜか毎回アクセス違反と言われてしまいます
本当にタイミングもデバッグモードで止めても意味がわからないままです
今まで動いていたのに敵を追加した瞬間に動かなくなりました

コード:

class EnemyEx :public CObject{
protected:
	int cnt;
	float x, y;
	float a, sp;
public:
	EnemyEx(float x,float y,float a,float sp):CObject(O_ENEMY,0.3){
		this->x=x;
		this->y=y;
		this->a=a;
		this->sp=sp;
		this->cnt=0;
	};
	virtual ~EnemyEx(){}

	float GetX(){
		return this->x;
	}
	float GetY(){
		return this->y;
	}

	virtual void Move()=0;
	virtual void Draw()=0;
};

class Enemy_Kikibongo :public EnemyEx{
	int stop_time, restart_time;
	float Update_Angle;
	int state;
public:
	Enemy_Kikibongo(float x,float y,float a,float sp,int stop_time,int restart_time,float Update_Angle)
		:EnemyEx(x,y,a,sp){
			this->stop_time=stop_time;
			this->restart_time=restart_time;
			this->Update_Angle=Update_Angle;
			this->state=0;
	}
	~Enemy_Kikibongo(){
		delete this;
	}

	void Move();
	void Draw();
};

コード:

void Enemy_Kikibongo::Move(){
	this->cnt++;
	float angle=0;
	Player *pl=(Player*)Object_Manager::GetTask(O_PLAYER,0);
	if(pl!=NULL)angle=atan2(pl->GetY()-this->y,pl->GetX()-this->x);
	switch(this->state){
	case 0:
		this->x+=cos(this->a)*this->sp;
		this->y+=sin(this->a)*this->sp;
		if(this->cnt == this->stop_time){
			state=1;
			cnt=0;
		}
		break;
	case 1:
		if(this->cnt == this->restart_time){
			state=2;
			cnt=0;
			this->a=this->Update_Angle;
		}
		if(cnt == 0){
			for(int j=0;j<3;j++){
				for(int i=0;i<3;i++){
					Object_Manager::AddTask(new BulletEx(this->x,this->y,angle-PI2/48+PI2/48*i,5+j,B_SMALL,ORANGE,DX_BLENDMODE_ADD,255));
				}
			}
		}
		break;
	case 2:
		this->x+=cos(this->a)*this->sp;
		this->y+=sin(this->a)*this->sp;
		break;
	}
	if(cnt > 500)this->used=false;
}

void Enemy_Kikibongo::Draw(){
	MyDrawRotaGraph(this->x,this->y,1,0,en_bongoG[0],TRUE,1);
}
なぜアクセス違反と言われてしまうのでしょうか
毎回ゲーム作ろうとするたびに壁にぶち当たる

アバター
夢幻ノ月夜
記事: 143
登録日時: 9年前
住所: Stens;Gate世界線

Re: 何故かアクセス違反が起きる

#2

投稿記事 by 夢幻ノ月夜 » 8年前

夢幻ノ月夜 さんが書きました:なぜか毎回アクセス違反と言われてしまいます
本当にタイミングもデバッグモードで止めても意味がわからないままです
今まで動いていたのに敵を追加した瞬間に動かなくなりました

コード:

class EnemyEx :public CObject{
protected:
	int cnt;
	float x, y;
	float a, sp;
public:
	EnemyEx(float x,float y,float a,float sp):CObject(O_ENEMY,0.3){
		this->x=x;
		this->y=y;
		this->a=a;
		this->sp=sp;
		this->cnt=0;
	};
	virtual ~EnemyEx(){}

	float GetX(){
		return this->x;
	}
	float GetY(){
		return this->y;
	}

	virtual void Move()=0;
	virtual void Draw()=0;
};

class Enemy_Kikibongo :public EnemyEx{
	int stop_time, restart_time;
	float Update_Angle;
	int state;
public:
	Enemy_Kikibongo(float x,float y,float a,float sp,int stop_time,int restart_time,float Update_Angle)
		:EnemyEx(x,y,a,sp){
			this->stop_time=stop_time;
			this->restart_time=restart_time;
			this->Update_Angle=Update_Angle;
			this->state=0;
	}
	~Enemy_Kikibongo(){
		delete this;
	}

	void Move();
	void Draw();
};

コード:

void Enemy_Kikibongo::Move(){
	this->cnt++;
	float angle=0;
	Player *pl=(Player*)Object_Manager::GetTask(O_PLAYER,0);
	if(pl!=NULL)angle=atan2(pl->GetY()-this->y,pl->GetX()-this->x);
	switch(this->state){
	case 0:
		this->x+=cos(this->a)*this->sp;
		this->y+=sin(this->a)*this->sp;
		if(this->cnt == this->stop_time){
			state=1;
			cnt=0;
		}
		break;
	case 1:
		if(this->cnt == this->restart_time){
			state=2;
			cnt=0;
			this->a=this->Update_Angle;
		}
		if(cnt == 0){
			for(int j=0;j<3;j++){
				for(int i=0;i<3;i++){
					Object_Manager::AddTask(new BulletEx(this->x,this->y,angle-PI2/48+PI2/48*i,5+j,B_SMALL,ORANGE,DX_BLENDMODE_ADD,255));
				}
			}
		}
		break;
	case 2:
		this->x+=cos(this->a)*this->sp;
		this->y+=sin(this->a)*this->sp;
		break;
	}
	if(cnt > 500)this->used=false;
}

void Enemy_Kikibongo::Draw(){
	MyDrawRotaGraph(this->x,this->y,1,0,en_bongoG[0],TRUE,1);
}
なぜアクセス違反と言われてしまうのでしょうか
解決しました
ただブレンド方式の引数の前に描画優先度の引数を追加したことを忘れてて
ブレンド方式に小数を渡していたのが原因でした
毎回ゲーム作ろうとするたびに壁にぶち当たる

閉鎖

“C言語何でも質問掲示板” へ戻る