Section of code causes IDE to timeout?

Hello,

I am having a strange problem…

I am trying to upload code to a non-official mega. However, it times out. If I try to load the blink sketch, that will load fine. I was able to narrow the problem down to this section of code:

void christmasTwinkle() {
   zSpeed = 100;
  int ranamount = 1000;                                           // The higher the number, lowers the chance for a pixel to light up.                                        // Standard delay value in milliseconds.
  byte fadeval = 255;                                        // Fade rate
  static byte color;
  static boolean justonce;
    
                 // Make sure we're at least utilizing ALL the LED's.
  int idex = random16(0, ranamount);
  
  if (idex < NUM_LEDS) {     // Only the lowest probability twinkles will do.
    byte value = random(100, 255);
    byte saturation = random();
    if (color == 0) {
      color = 96;
    }
    else color = 0;
    
    if(idex < NUM_LEDS && idex > 0){
    leds[idex] = CHSV(color, saturation, value);
    }
    if((idex + 1) < NUM_LEDS && (idex + 1) > 0){
      leds[idex + 1] = CHSV(color, saturation, value);
  }
  }
    if (zFlag == 1 && justonce == 1) {
    justonce = 0;
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
    if((i + 1) < NUM_LEDS && (i + 1) > 0){
    leds[i + 1].nscale8(fadeval);
    }
  }
    } else if (zFlag == 0) {
    justonce = 1;
  }
}

If i comment this out, the sketch will compile fine… Which is strange, since i have this function right above it, which performs the same action but just in different colors…

void patrioticTwinkle() {
  zSpeed = 100;
  int ranamount = 1000;                                           // The higher the number, lowers the chance for a pixel to light up.                                        // Standard delay value in milliseconds.
  byte fadeval = 255;                                        // Fade rate
  static byte color;
  static boolean justonce;
    
  //if (ranamount >NUM_LEDS) ranamount = NUM_LEDS;               // Make sure we're at least utilizing ALL the LED's.
  int idex = random16(0, ranamount);
  
  if (idex < NUM_LEDS) {     // Only the lowest probability twinkles will do.
    byte value = random(100, 255);
    byte saturation = random();
    if (color == 160) {
      color = 0;
    }
    else color = 160;
    if(idex < NUM_LEDS && idex > 0){
    leds[idex] = CHSV(color, saturation, value);
    }
    if((idex + 1) < NUM_LEDS && (idex + 1) > 0){
      leds[idex + 1] = CHSV(color, saturation, value);
  }
  }
    if (zFlag == 1 && justonce == 1) {
    justonce = 0;
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
    if((i + 1) < NUM_LEDS && (i + 1) > 0){
    leds[i + 1].nscale8(fadeval);
    }
  }
    } else if (zFlag == 0) {
    justonce = 1;
  }
}

and this section of code doesn’t cause the IDE to timeout…

Any ideas? My entire code is below.

Could it be that your code’s too big to fit?

Nope...

using 10 percent of storage space.... and 25 percent of sram *global variables

Sketch uses 27,360 bytes (10%) of program storage space. Maximum is 253,952 bytes.
Global variables use 2,122 bytes (25%) of dynamic memory, leaving 6,070 bytes for local variables. Maximum is 8,192 bytes.

Very likely the code compiles to have three exclamations in a row. If that is the case you will have to update the bootloader (and find a better vendor).

Im waiting for another board to arrive so i can upload the boot loader, but when you say three exclamation points, is that in the compiled code or it my sketch's code?

I read that somewhere else but i didn't see where i had three exclamation points.

Also, what can i add to get rid of the three exclamation points for the time being (i tried adding a few extra variables, for kicks, but didn't seam to change anything, I also try changing the name of the function and the function type (void to int)...

Either.

You could try disassembling using avr-objdump.