CODEA Stability/Lost Code

Firstly this isn’t a rant - I am a new user of CODEA and massively enjoy entertaining myself with coding during the lockdown in the UK. Learning LUA and coding has kept me sane (saner?) over the last few days.

I did a search regards losing code and saw some discussion but it goes back to 2019 - Oct. I had just finished coding quite a bit of code in a new class. Hadn’t run the code - but when I switched to another tab - my new tab just was no longer in the tab bar. Searched CODEA in the files app but it was gone.

First time I have had a problem with the app - but it is worrying. I am using the IDE on my iPad Pro (not the browser alternative). Have the latest iPadOS patches. Definitely not available - just gone!

Is this a very rare event - or does this happen to other folk…

@Mike2304 I’m very sorry this happened to you. It must be frustrating. Just to get the steps down so I can try to find the cause:

  1. Create a new tab
  2. Write code
  3. Switch tabs without running
  4. Newly created tab disappears

I imagine this doesn’t happen all the time, I’ll put the editor through some testing to try resolve it

These lost code issues started happening around the same time we adopted Apple’s UIDocument framework instead of manually saving your code

No worries - appreciate the reply. Will keep an eye on it and let you know if it occurs again. Thanks for a cool product though. Have enjoyed using it.

@Simeon I mentioned this before, but I don’t know if you didn’t see it or you just dismissed it. But it might be helpful if there was a SAVE icon at the top of the editor. That way a person could just tap the button as they’re writing code. They could tap the icon every few minutes or just before they execute the code. I know you have the long press prompt on the run icon, but having a separate SAVE icon might be easier. It wouldn’t be much different than the Save Draft here in the forum that is very handy.

@dave1707 unfortunately even the Save & Run sometimes doesn’t work as expected. I didn’t dismiss your earlier suggestion, but I think I have a more foundational bug relating to UIDocument saving that I need to track down

When I was using my own autosaving code to the local filesystem this wasn’t happening. I moved over to Apple’s autosave system in order to support cloud documents and modern filesystem extensions but it has led to this

The technical details of the way autosave works in modern iOS “documents” is that if you have undo tracking (which we do) then for every step you track which is undoable, you notify the document that something has been “done.” iOS then schedules an autosave operation to happen asynchronously in the background. The “document” (in this case, Codea project) can always provide its latest data for iOS to use to write it to disk

This autosave operation is supposed to be resilient to application suspends (i.e., closing Codea) but sometimes appears to lead to incorrect behaviour. This could be down to what I’m doing and how I’m using (or misusing) the document system

The problem I’ve had with force ‘saving’ UIDocuments in the past is that sometimes it can get stuck, never saving. This used to manifest as a bug in Codea that could cause it to hang when closing a project (at the time I used to force a save there, but this was not necessary)

At the moment I’m re-writing the editor for the new iPad keyboard / trackpad stuff and I’ll be re-reading the saving code and how creating and switching tabs might interact with the saving system (as well as the issue that can cause stale code to run when you hit the play button)

@Simeon - I have had an issue with save & run today. After editing on pressing/holding the run button Codea crashed. I must mention that I was linked to my Mac using Airdrop for cut and paste. In the past I have struggled with it getting no response at times but that could be a feature of poor response to touch on my system - do dry hands affect poor touch response CVD-19 and hand washing drying them up,!!!

@Bri_G I’ve occasionally had problems with dry hands ( finger) long before the virus. My way around that was to lick the tip of my finger to moisten it.

Yikes, this just happened to me. Luckily, it was with a brand new project with minimal code in a new tab, so no big loss. But, the entire tab is just gone. It disappeared when I switched back to the Main tab.

@brianolive thanks for the report I’ll focus extra on the code around tab creation and saving

Maybe I can contribute slightly.

Usually before these happens, I experience:

  • Lagging colors in the code editor.
  • Long loading times.

I’ve experienced this from different perspectives:

  • Opening app executes the new added code, but closing the app again results in code reset (new added parts disappear)
  • Closing the project instead, does not really help.
  • I did not try terminating Codea, yet. My plan was to do so next time similar things happen.

@MIke2304 I suggest to use the “save and run”-tool always. If the editor starts to lag you will not experience that much code loss.

I don’t know if this is the right place to log this one also, but I’m still getting the issue where sometimes a previous version of the project gets run (and saved). I have to exit the project and go back in, whereupon my latest changes are lost. (I’ve gotten to the point where if I recognise that this has happened, I copy the current tab to the clipboard and paste it back in when I resume the project - Save&Run doesn’t seem to help.)

That’s with the current release on the App Store.

@LoopSpace @Anatoly thanks for both of those reports, very helpful

Just happened again. Entire class disappeared. Only noticed when I tried to run the app and it failed as it could not find the class at all. Very nervous about doing significant development if modules can just “disappear”. Please try and sort this out.

@Anatoly thanks for the suggestion. The problem I have is I had not edited the class file I lost for sometime. I was working on another part of the app. When I hit run - it failed as the unedited class file had disappeared into the ether. I have noticed that my Bluetooth keyboard lags and gets unresponsive at times - and I have to lift it off the connector and reconnect it. Still doesn’t explain how an entire module can disappear rather than a portion of new code that hasn’t been saved. Will hang back on developing until a solution is found.

All - I must say that most of the time this is not happening and, I tend to program in smaller chunks frequently checking for the change when run, occasionally my edits are lost as described by @Loopspace. Pressing and holding the run button usually resolves this but I have seen crashes (as mentioned above) and sometimes poor response (no save option) to the touch.

On the touch - could this be related to the capture area for the button touch - broad finger tips could be a contributor if the OS gets two different touch requests in quick succession? Could you add run to the pull out parameter window? or have a drop down window control with save and run buttons (well spaced) on it?

@MIke2304 if you long press on the play button in the upper right you will be given the option to “Save & Run.” This will force a save prior to running. Originally I added this option for self-modifying code (i.e., code which needs to read itself)

Sorry about these issues, I’ll look into them as soon as possible

@Bri_G possibly. I’ll be looking into this closely very soon. I’m in the middle of migrating a lot of the editor code so as soon as that’s done I’ll be on to the save issue

@Simeon - I thought I would give you my feedback on the lost code saga.

  • It is always the last tab (on the right) that disappeared. I have created a dummy module on the right as a safeguard.
  • It appears that these events may be related in some way to my Bluetooth keyboard. Weird stuff happens when when software keyboards pop up - such as the emoji keyboard (which I have turned off and things seem better).
  • I am still a tad confused that a module that has been saved can get deleted - as the file is not visible in the files app or CODEA. So it is a terminal event.

Don’t know if all the above are read herrings but it may help you track the problem down.

Stay well everyone.

@MIke2304 when you say not visible in the files app, you shouldn’t be able to see the individual tabs in the files app — you just see the MyProject.codea package. If you take this onto a Mac you can right click on it and choose “Show Package Contents” to see which code files are inside it