ページ 11

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

Posted: 2016年5月03日(火) 23:14
by 夢幻ノ月夜
なぜか毎回アクセス違反と言われてしまいます
本当にタイミングもデバッグモードで止めても意味がわからないままです
今まで動いていたのに敵を追加した瞬間に動かなくなりました

コード:

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);
}
なぜアクセス違反と言われてしまうのでしょうか

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

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

コード:

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);
}
なぜアクセス違反と言われてしまうのでしょうか
解決しました
ただブレンド方式の引数の前に描画優先度の引数を追加したことを忘れてて
ブレンド方式に小数を渡していたのが原因でした