Unable to upload after enabling wdt

I’ve for a Mega 2560 and used the following in my code:

#include <avr/wdt.h>

After compiling and uploading my program would no longer run - when I plug the arduino in now the led just flashes continuously. I cant even upload the blink a led example. =(

First why did this break my program, and more importantly how do I recover from this?

only with these 3 lines it is hard to say what went wrong. A possibility is that the WDT resets the chip when you try to upload new code.

IIRC one trick is keep the reset button pressed and release it when uploading starts

other trick might be - http://arduino.cc/en/Tutorial/ArduinoISP -

Thanks - looks like I"ll have to reprogram it :(

I tried the reset trick - didnt work.

Update: Got it working - reset button didnt help, but if I unplugged the USB and then plug it back in and quickly hit upload then it worked.

Now that I got it working with blink a led I tried a single wdt program and its def not working on the Mega.

#include <avr/wdt.h>

void setup() 

void loop()

By my under standing the WDT should trigger after 8 secs and reboot the Arduino. Well after 8 secs it reboot and then causes the endless looping.
A reset button does nothing and I have to proceed to unplug the USB and then replug i and quickly reprogram.

Is it a bug or am I missing something?

Ok, after much reading up it looks like a bug in the bootloader for the Mega2560.

I uploaded a new version from here https://github.com/arduino/Arduino-stk500v2-bootloader

and its fixed the problem.