Odd behavior in subroutine with interrupt

I’m getting an odd bug with the subroutine SendAddrData in the following code.

Basically, my loop enters the subroutine with two arguments and waits for an external interrupt to be thrown. Once it is, it sets two ports to specific values and then exits. When I first tried it, it would work correctly until it was calling data from the const tables using the for loop. It would pull seemingly random values from the two tables and set PORTF and PORTK to those bytes. This subroutine started working when I put a Serial.print statement inside it. Later I realized it would also work with any delay() or delayMicroseconds(). Is this a compiler/optimization bug?

const uint8_t tableHi[] = 
const uint8_t tableLo[] = 
                                                     //These tables were taken from http://www.freewebs.com/the_bott/NotesTableNTSC.txt
                                                     //tableHi is the top 3 bits for $4003, tableLo is the bottom 8 bits for $4002

volatile boolean state = false;                      //switch to make sure I write values at the right time

void writeData(){                                    //routine to switch state while NES is BRKing
  state=true;                                        //switch state

void sendAddrData(uint8_t address, uint8_t data){    //routine to send address and data along to '245s when interrupt is thrown
  state = false;                                     //set switch
  while (state!=true);                               //wait for interrupt to throw switch back
  PORTF = address;                                   //write address variable to register
  PORTK = data;                                      //write data variable to other register
/*I have no clue why, but I have to include this delay somewhere in 
this routine, else the sound will be messed up. It works literally anywhere. The reason I added this in the first place is 
lost to me. It came as one of those 'flash of inspiration' moments, like when you're puzzling over something at 3am, and a 
little voice tells you to insert this piece of code here, and it works. idk lol. compiler optimization error?*/

void setup() {
  DDRF = 0xFF;                                       //initialize registers as output
  DDRK = 0xFF;
  PORTF= 0x15;                                       //Good initial values
  PORTK= 0x0F;  
  attachInterrupt(2, writeData, RISING);             //begin interrupt function on pin 21, calls writeData on falling edge

void loop() {                                        //main loop
  sendAddrData(0x15, 0x1F);                          //Turn on all channels
  sendAddrData(0x00, 0xBF);                          //Turn square wave to max volume, 50% duty, etc
  sendAddrData(0x01, 0x08);                          //Negate sweeps
  for(int n; n < sizeof(tableHi)/sizeof(int); n++)
    sendAddrData(0x02, tableLo[n]);                  //increment through the note table posted above, low bits
    sendAddrData(0x03, tableHi[n]);                  //increment through the note table posted above, high bits
    sendAddrData(0x1F, 0x00);                        //end write, NES does its thing now
    delay(125);                                      //note duration
  sendAddrData(0x15, 0x00);                          //silence all channels
  sendAddrData(0x1F, 0x00);                          //end write

It could be your external interrupt is noisy and is generating multiple edges, and the delay serves to "debounce" this.

You also have sizeof(tableHi)/sizeof(int) in your code, but the denominator really should be sizeof(uint8_t). But I don't think that's the problem.

-- The Quick Shield: breakout all 28 pins to quick-connect terminals

for(int n[glow] = 0[/glow]; n < sizeof(tableHi)/sizeof(int); n++)