View Single Post
  #5   Spotlight this post!  
Unread 22-03-2009, 11:38
heydowns's Avatar
heydowns heydowns is offline
Registered User
AKA: Jeff Downs
FRC #1511 (Rolling Thunder)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Ra-Cha-Cha
Posts: 142
heydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond reputeheydowns has a reputation beyond repute
Re: HELP: Robot Crash in Autonomous

Quote:
Originally Posted by Shadow503 View Post
Code:
/**
 * Call this method to drive
 * @param speed a double describing the speed		-15fps to +15fps
 */
void Autonomous::procTable(int AutoMode) {

// ........

			if(cur_command + 1 < sizeof(currentCommand)) {	//there is another command to run
				cur_command++;	//increment to next command
				currentStateTime = 0; //move on to next state
			}

// .........

}

This is at least part of the problem you are experiencing. "sizeof(currentCommand)" will not give the size of the commands array. sizeof evaluates at compile time to the size of a type, or, when used with a variable, the type of the variable. currentCommand's type is "struct Command *". So, the sizeof (regardless of which command table is chosen to have currentCommand point to) will always evaluate to the size of a struct Command pointer (probably 4). This could be greater than the actual size of your command table, causing your program to potentially walk off the end of an array.

The easiest way to change this would be to add another command type that signifies the end of the command table. When your autonomous code sees that command as it processes the table, it knows it has reached the last entry.
Reply With Quote