AFreakingBear
TL;DR:
> **Never delete the first line of the Arduino Extension file in OpenPLC Editor!**
> It is a critical bug, already replicated and documented.
> A patch/fix in the Editor core is suggested to prevent loss of work.
Translated with DeepL.com (free version)


When working with OpenPLC Editor, there is a critical issue that can lead to **total loss of content** in the Arduino extension file (`arduino_ext_X`).
This issue occurs when the user **deletes the first line of the file**, which normally contains a special comment, such as:
```cpp
//////////////////////////////// sketch section ////////////////////////////////
```
If this line is removed (for example, when pasting new code from VSCode/Copilot, or when cleaning manually), **when changing windows or switching POUs, OpenPLC Editor deletes all the contents of the file**.
The user thus loses all the work done on the Arduino extension.
How to replicate the bug:
1. Open OpenPLC Editor and go to the Arduino extensions section.
2. Delete all the contents of the file, including the first line (the special comment).
3. Paste or write your new Arduino code without that first line.
4. Switch windows or switch between POUs.
5. The Arduino extension file is empty—all code disappears.
## Possible cause
The Editor relies on the presence of the special line to correctly identify and manage Arduino extension files.
Without that line, the parser does not recognize the content as valid and deletes everything when saving/loading.

Suggested fix
- The Editor should **protect** the user from this error, for example:
- Validate the presence of the special line when saving/loading.
- Automatically add the line if it is missing.
- Warn the user if they try to save without the marker.
## Impact
- May cause **irrecoverable loss of work** for those developing Arduino extensions in OpenPLC.
- Replicable in any OpenPLC Editor installation.
- Affects both advanced and novice users.
Reply 1 0
thiagoralves
Thanks for the report! Since we’re working on OpenPLC Editor v4, it is very unlikely that this bug will be fixed on v3. The v4 implementation is totally different, so we wouldn’t be able to reuse any of the work spent on v3
Reply 1 0
Write a reply...
Reply