My computer crashed in the middle of a sketch upload from Arduino IDE to my Leonardo. I got the blue screen. After I got my computer running again, I couldn't but notice that my .ino file was filled with NULL. This has been mentioned before and people haven't got any answer to what's going on here. I just hope that someone has found a solution for this since last time someone posted about it. There are no automatic backups, are there? How on earth can a bug fill the file with NULL and save it? I'm using IDE 1.8.13
Yes, I'm really pissed off! I mean, how can one prevent something like this from happening? Every time you save, you have to take a backup. Don't ever hit the upload button before you have saved and taken a backup.
No. However, there is a chance that there is a temporary copy of your sketch left on your computer.
When the Arduino IDE compiles your sketch, it first must do some minor preprocessing to turn it into valid C++. That file is stored under your operating system's temporary folder in a path something like this:
(where <user name> is your user name, 281921 is some random number and MySketch is the name of your sketch)
That is the Windows path, but it will be the equivalent on other operating systems.
So you should do a check through that temporary folder to see if you can recover your sketch. The Arduino IDE usually cleans up the temporary folder on exit, but if your computer crashed then the IDE likely didn't have a chance to clean up and it may still be there. If it is, you can open the file up in any text editor.
There will be some small changes from the sketch preprocessing but we can definitely help you to restore it to its original state.
I thank you so much for 3 saved workdays! I marked your post as the solution, even though it won't fix the underlying problem with the IDE destroying files. It scares me that no one has mentioned that this bug would have been fixed. Or the event recreated by someone who can trace the bug. So is it plausible that the bug still is present in the newest IDE?
But yeah, I found my code with those peculiar changes you mentioned. I'm most sure I can restore it. Thanks again.
And I'm going to implement the awkward backing up routine from now on.
This is odd. The blue screen is a safety feature in Windows, whereby it stops dead the entire OS specifically to avoid corrupting user data (obviously data in RAM can't readily be saved).
Writing nulls to the file would suggest some processing goes on after the blue screen crash, unless the IDE routinely writes nulls to the file as part of its normal operation, and the crash occurred at just the wrong moment.
Any blue screen crash is a cause for concern. I use Windows heavily and I can't remember the last time it blue-screened; it must be a good fifteen years ago, maybe more. The only way I know of to blue-screen a PC is to have a bad driver installed (because they run in kernel mode) or - much more likely - a hardware fault. Therefore I'd be looking closely at the various health indicators in your PC for signs of trouble. You can get programs that display all sorts of interesting stuff about fan speeds, temperatures, clock speeds, etc.
In the Start menu, type 'View reliability history' and check out the Reliability Monitor.
Yes. But I only wanted to know what your setting was.
It might very well be Windows that overwrote the file with whatever when it crashed and not the IDE. I'm not defending the IDE, there have been reports here on the forum about empty files. But in your case I rather suspect Windows.
The crash happens when I compile and upload a sketch. I have a Leonardo, which will read MIDI signals from the computer and wil perform actions on 4 servos via I2C and a PCA9685 driver.
Could it be that the Leonardo is the crashing part and it manages to send random signals to the computer, which interprets them as keystrokes, which overwrites the content in the file open in the IDE editor? Before the computer crashes due to the chaotic input, there's a ctrl+s coming in?
As far as I know, an operating system does not immediately write the file to disk when you tell it to save the file. I do not exactly know how it all works but, as far as I understand it, the file is 'queued' for saving. If you get a blue screen and memory is corrupted, that queued file in memory can be corrupted (either literally or a pointer that points to the wrong memory area).
Yes, that's a good theory. It shouldn't have written it back to the disk, though, because that's the whole point of stopping the OS with a blue screen. However, it obviously happened. I don't suppose we'll ever know why.