I wrote a new sketch and made a mistake in the code that tries to access an invalid index in an array. As a consequence my COM port appears when I connect the arduino (Leonardo R3) but as soon as the sketch starts the COM port disappears.
I have confirmed it is not the PC by connecting another arduino that only has the blink sketch installed.
I've been trying for hours trying to prevent the sketch from executing, or even prevent the COM port from going away, but have not had any success.
I've already tried different scenarios while holding down the reset button but nothing is working for me.
Is there anyway I can work around this problem so I can upload the corrected sketch.