odd wii crash
November 26, 2010 07:53AM
After hours of working on the code to detected when the ball hits a wall at any angle, I finaly got it oo work, but now I am getting an odd problem. Whenever I put a wall in a level in my game, the wii crashes when I finish the level. I have traced the crash as far as I could, and found out that this only happens when I call my wallDistance function. I have looked at the code, and non of it looks like it would cause a code dump, but I could be wrong. Here is the code for the wallDistance:
float wallDistance(int lvlnum,int wallnum,bullet myBullet){
	float X;
	float Y;
	float a;
	float b;
	float c;
	float d;
	float X1;
	float Y1;
	float X2;
	float Y2;
	float newX;
	float newY;
	
	float mew;
	float final;
	
	X = myBullet.getX();
	Y = myBullet.getY();
	
	testWall.X = X;
	testWall.Y = Y;
	
	X1 = levelList[lvlnum].wallX1[wallnum];
	Y1 = levelList[lvlnum].wallY1[wallnum];
	X2 = levelList[lvlnum].wallX2[wallnum];
	Y2 = levelList[lvlnum].wallY2[wallnum];
	
	if(X1==X2){
		final = abs(X-X1);
		newX = X1;
		newY = Y;
		
		testWall.X = newX;
		testWall.Y = newY;
		
	} else {	
	
		a = X1;
		b = Y1;
		c = X2-X1;
		d = Y2-Y1;
		
		//The code below finds the distance between the ball, and the line given
	
		mew = ((a*d)+(c*Y)-(c*b)-(d*X))/((c*c)+(d*d));
		final = sqrt(((c*mew)*(c*mew))+((d*mew)*(d*mew)));
	
	
		//newX and newY are the X and Y locations of the closes point on the line
		newX = X+(mew*d);
		newY = Y+(mew*(-c));
		
		testWall.X = newX;
		testWall.Y = newY;
		
	}
	/*The code below checks to make sure that the ball is colliding within the wall
	The way the if statements below work is each statement check to make sure that the
	ball is within the wall line, and then the if will return true if it isn't
	that way I can use a simple return -1; to symbolize that the ball is not colliding with the wall
	the reason for all of the Xn>Xn and Yn>Yn statements is that the range of values to check
	if the ball is within the wall is different if Y1>Y2 then if Y2>Y1
	-2 is returned if both X's and Y's are equal to each other */
	
	if(X2 > X1){
		if(Y2 > Y1){
			if(!((newX < X2)&&(newX > X1)&&(newY < Y2)&&(newY > Y1))) return -1;
		} else if(Y1>Y2){
			if(!((newX < X2)&&(newX > X1)&&(newY > Y2)&&(newY < Y1))) return -1;
		} else {
			if(!((newX < X2)&&(newX > X1)&&(newY==Y2))) return -1;
		}
	} else if(X1 > X2){
		if(Y2 > Y1){
			if(!((newX > X2)&&(newX < X1)&&(newY < Y2)&&(newY > Y1))) return -1;
		} else if(Y1>Y2){
			if(!((newX > X2)&&(newX < X1)&&(newY > Y2)&&(newY < Y1))) return -1;
		} else {
			if(!((newX>X2)&&(newX Y1){
			if(!((newY < Y2)&&(newY > Y1))) return -1;
		} else if(Y1 > Y2){
			if(!((newY > Y2)&&(newY < Y1))) return -1;
		} else {
			return -2;
		}
	}
	
	return final;
}

This is the code for the level that calls this function:
for(i=0;i < levelList[lvlnum].numWalls;i++){
				wallDist = wallDistance(lvlnum,i,shootingBullet);//If I replace this line with wallDist = 80; then the wii doesn't crash
				if((wallDist <= 16)&&(wallDist > -1)){
					bulletAlive = false;
					shootingBullet.resetBullet(initX,initY,.000000001,0,0,0);
				}
			}
When a level is completed, then all that happens is that the level function returns to the caller. for example:
void runLevel(args...){
do{

} while(levelDone==false)
}
For this reason, I think that my wallDistance function is somehow corrupting the stack, and placing the wrong return values for my runLevel function, but I am not sure where that problem would even be at. All that is happening in that function is some arithmetic functions.
Thank you.
Re: odd wii crash
November 26, 2010 10:16AM
Maybe the wallDistance isn't the problem but the resetBullet is?
Re: odd wii crash
November 26, 2010 05:42PM
I don't think the problem could be in resetBullet, because the same exact function is called whenever the ball exits the screen, or hits a planet, and there isn't a problem in any of those levels. But just to be sure, here it is:
void bullet::resetBullet(float initX,float initY,float initspeed,float initangle,float initaccel,float initaccelAng){
	X=initX;
	Y=initY;
	speed=initspeed;
	angle=initangle;
	accel=initaccel;
	accelAng=initaccelAng;
}
Re: odd wii crash
December 02, 2010 02:51AM
I figured it out. All I had to do was pass a pointer to a bullet object, and not a bullet itself.
Sorry, only registered users may post in this forum.

Click here to login