Can I clear the codea image/text cache?

I got some problems with my assets, essentially texture image and json text. I do a lot of save and reload. And now some images and texts are empty for the lua code, but not for the assets explorer. For example: I’m using the readImage function. On the editor side, I can see my image in the assets explorer, but in the code the function return nothing.
I read somewhere that codea cache some stuff, I would like to now how to clear that cache.

try running the function collectgarbage() to get rid of assets you have deleted.

I already tried that.
Doesn’t change anything.

collectgarbage is for memory management, not storage, it has no effect on the contents of the various asset folders such as Dropbox and Documents. So you’re saying that you deleted items from these folders, but they still show up in the asset pickers, have I understood you correctly?

A few questions:

  1. which asset folders are they in? Dropbox, Documents, or the Project folder?

  2. How did you delete the assets (by pressing edit, delete, within the asset picker? Deleting them remotely, ie removing items from your Dropbox and then pressing sync? Or using io and file libraries)?

  3. What is the file extension of the assets? For text assets, the asset pickers and readText commands only see files with extension .txt. You can put files with other extensions (.json or whatever ) in these folders, but you won’t be able to see or edit them in the asset picker or open them with readText, you need to use Lua io and file libraries to work with these.

I’m saying the file is not the same in the asset pickers and while executing by my lua code.

I’m trying different things: set nil, then create a fresh new image/text, reimporting the image/text from a project copy. Some times, in my application I got the previous version of the image/text.

I’m able to fix the problem by renaming the file, but I don’t want to do that every times. I will run out of name ideas.

  1. I’m using the “Project” folder.
  2. set nil with saveImage or saveText
  3. I always use .txt

About 2, does that work for you? Other users reported that using saveText with nil crashes Codea:

http://codea.io/talk/discussion/comment/62055/#Comment_62055

Also, see my comment here: http://codea.io/talk/discussion/comment/62074/#Comment_62074

It seems that os.remove doesn’t delete the file totally, just wipes its contents. I would avoid os.remove and os.rename tbh, particularly with assets in the Dropbox. If I remember, the issue I had was this: I renamed an asset with os.rename (what I was doing was stripping the .obj extension on the file name and replacing it with .txt, so that I could see the file with the asset picker and readText, so that eg myModel.obj became myModel.txt). At first, everything seemed fine with the renaming. But then, if I added a file back into the Dropbox with the same file name as the original (in other words, I re-exported the original myModel.obj file from Blender to Dropbox), the io and file commands couldn’t see the myModel.obj file. If I renamed the file in the Dropbox app to anything else, say myModel2.obj, then io and file could see and read the file again. I’m no expert in file systems, but it was as if, even though os.rename had apparently successfully renamed the file from myModel.obj to myModel.txt, the old myModel.obj namespace was still being occupied in some file directory somewhere, and no new file called myModel.obj could be accessed in the folder. So, don’t use os.rename, as it will mess up your asset folder structure. I don’t know if this is related to your issue, but it seems similar to what you’re seeing (particularly the thing you said about having to come up with new file names)

We never did get round to filing that support ticket for saveText nil. I’ll do that now.

Is there a particular reason why you need to delete assets programmatically (ie within your code?) ie does your project let the user create/ save/ delete images and other assets? If not, the safest way to delete is in the asset picker itself (press edit in top right corner, select the assets to be deleted, then press delete). Dropbox is also very handy for asset management, do all your changes on the remote, then just hit sync in Codea.

But if you’re writing, say, a painting application, then not being able to properly delete user-created assets from within the code is a problem.

Put nil in saveText do not work, but, I does for saveImage.

That’s exactly what I’m doing, create an application that can modify user-created assets, with an image and a tiles editor.

Thanks you for your comment.

Well, I fixed the problem with the image by removing the file with saveImage nil and recreate it.
I also fixed the reading problem of the text files by getting the content using io.read if readText return nil.

I’m glad you’ve found some fixes. Though something’s not right if readText can’t read a file. Just to confirm, the extension is just .txt (you’re not using a double extension like .json.txt?) Could you post some code that just shows this ReadText bug? Or is it too hard to reproduce the steps that cause this?

Ticket created for text deletion bug:

https://bitbucket.org/TwoLivesLeft/core/issues/370/savetext-name-nil-does-not-delete-text