The tricky thing about the boards with native USB functionality like your board is that the USB code that creates the CDC serial port is running on the same microcontroller as your sketch. This means your sketch code can break the USB code, or stop it from running. When that happens, it no longer presents a port.
That makes it so you can't upload normally any more. However, the situation is really not so bad because there is an independent program called the bootloader in a separate section of memory from your sketch, and that program has its own USB CDC code. So even if the sketch is completely broken, you only need to activate the bootloader via the double reset technique and you will get a port back and be able to upload again, as you discovered.
It's far more likely that the problem is with the code in the specific sketch you are using rather than that your board was "corrupted". You can verify this by uploading a simple sketch like File > Examples > 01.Basics > BareMinimum. If the problem no longer occurs when you use a sketch like that, you will know that your previous sketch code is the cause. At that point, your task is to identify exactly which part of the sketch code is breaking the USB and fix it.
You should note that this behavior is normal and expected in some cases. For example, a sketch that puts the microcontroller to sleep will inevitably cause the port to disappear because if the microcontroller is asleep then it can't also be running the USB stack.