r/arduino 6d ago

Arduino IDE dropping code

I have discovered the Arduino IDE drops code when the screen saver kicks in and locks then the screen. On unlock, my code is gone!!

Ive had it happen several times now and its taken me this long to discover whats going on!

This is a HUGE bug.
Has anyone else had this happen?

EDIT: using ver 2.3.7

12 Upvotes

24 comments sorted by

8

u/lovesrayray2018 6d ago

I personally havent seen this happen, but thats probably because i am on IDE 2+ which has auto save enabled on every edit (unless u turn it off). If you are on IDE 2+ you should be able to reopen the saved file right?

5

u/Charlie_Macaw 6d ago edited 6d ago

I’m using 2.3.7 and deliberately have auto-save turned off otherwise everything you type gets saved and if there is an error in your code you can only undo (ctrl-Z) back to the last (auto) save which is sometimes not far enough to undo, so I prefer to manually save but if you haven’t saved and (for example) the phone rings and you get talking and the screen saver kicks in, BAM! , your code/changes have gone!!

10

u/async2 6d ago

look into git and how to use it. then you're never afraid to save your work.

-2

u/Charlie_Macaw 6d ago

I’ve seen and considered GIT previously some time ago, but for me as a hobbyist and copying and pasting back and forward to flash an ESP32 using git seems laborious

6

u/gdchinacat 6d ago

You really should use git. It is not only for working on shared code bases, although it does that very well. You should be able to learn the basics in 15 minutes. One of the things it is really good at is when you aren't sure if the code you are working on will end up working. You can commit it to a branch and decide later if you want to merge it to the main branch.

One thing to note though is it isn't a magic bullet. You need to commit often to be able to rollback...you can only restore to commits. If you want something more fine grained without explicit commits many IDEs (IIRC arduino IDE is one of them) that have a 'local history' feature that essentially have a shadow version control that is committed to often (every save). With autosave this means you can restore practically every version. The challenge becomes finding the one you want. I haven't used the arduino IDE much and it was a while ago...I'm a professional coder and have my own IDE set up that I use instead. I'm pretty sure it's based on Eclipse (which is what I use) which does have local history, so I'm pretty sure the arduino IDE has it as well.

3

u/async2 6d ago edited 6d ago

What are you copying? There is no need to copy stuff to flash an esp from a git tracked project.

4

u/ScienceNerd0 6d ago

You don't copy and paste code on Github.

You type commands in a terminal to push/Pull code directly into a folder. Or use the desktop app version of it.

It's a great tool for version control, especially as your code grows. I'd highly recommend it.

2

u/ripred3 My other dev board is a Porsche 6d ago edited 6d ago

you really should use git. this is exactly what the decades old subject/industry/products related to version control have been about and what the proper solution to this common engineering problem is. If you write a lot of code and need to be able to go back to previous working versions it is the only sane way to approach computer program source code versions whether it is for my personal hobby files or when I am at work as a developer.

On a possibly related note I would really look deeper into exactly what that screensaver is doing! 😉

Does your screensaver require a password to unlock the desktop? I'm curious if requiring that (or not) makes a difference.

When you have the IDE open and the screensaver kicks in and then you bring it out of the screensaver does it completely remove the contents from the editor window that was displayed, does it only remove everything added since the last intentional save?

1

u/Timmah_Timmah 6d ago

Wow. I would disable my screen saver, but that's a pretty serious issue.

4

u/Fess_ter_Geek 6d ago

I use Notepad++ for Arduino coding and only use the IDE for uploading.

1

u/Several-Sign5777 6d ago

Same thing. In fact, you don't really need to download the IDE. You can write a macro and use AVRDUDE with Npp :)

3

u/gm310509 400K , 500K , 600K , 640K , 750K 6d ago

I have never experienced this. What happens if you change the screen saver to one of the standard ones (assuming you are using a third party one)?

FWIW, I mostly use IDE 1.8, but occasionally I used 2.3 and haven't noticed this issue. If you save your project, then let the screen saver kick in then move the mouse does it still happen? Is the saved project file "blank"?

4

u/Charlie_Macaw 6d ago

I have just this minute via a Google search found this:

https://github.com/arduino/arduino-ide/issues/2704

3

u/gdchinacat 6d ago

That's really appalling handling of that bug. A data loss bug has existed for over a year, it's considered an 'imperfection'. Typically data loss bugs are considered among the most severe and are fixed within days. *Especially* when the report identifies the exact commit that introduced it. This reinforces my decision to use a separate IDE and only use the arduino IDE to do uploads (because I haven't bothered to find or write a small script to do it).

3

u/Charlie_Macaw 6d ago

I have used ESPConnect to flash my ESP32 but I’m a newbie and not sure if it can be widely used across the board or if there are limitations

1

u/Several-Sign5777 6d ago

Excuse me, but is it essential for you to use the latest version of the IDE? Maybe you could switch back to the previous version and wait until the bug is fixed?

1

u/Delta_G_Robotics 6d ago

What operating system?

1

u/Charlie_Macaw 6d ago

Windows 11

1

u/hadashitday 5d ago

Check your USB cable and power supply first.

1

u/Charlie_Macaw 3d ago

USB cable and power supply for what ??

-1

u/jongscx 6d ago

Can you post screenshots?

2

u/Charlie_Macaw 6d ago edited 6d ago

Of what? An empty ARDUINO IDE window where my code used to be but now looks like a new sketch window freshly opened?

Sorry for the sarcasm but there is nothing to show you. What do you want to see???

-2

u/jongscx 6d ago

Yes, you obviously know how to replicate it. Show us before and after. Hell, record a video.

0

u/Charlie_Macaw 6d ago

No point. See the link below….