Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Apparent caching issue when reading the same image file twice, when image has changed in between
Started by cditto Jan 26 2010 03:52 PM

- - - - -
1 reply to this topic
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 22 posts
  • Corona SDK

I am having great success with everything I've been using in Corona, but I'm stuck on one issue.

The app that I am working on allows the user to select a custom background from their image gallery (I display it, take a screenshot, save it to the OS, then use the screenshot file) and everything works great the first time, but I seem to be experiencing a strange caching issue when the user changes his/her mind and selects a different background image a second time. I am overwriting an image file each time, but no matter how many times I change the image file, and re-read it, the image file only seems to be actually read the first time after the app is launched. When the app is re-launched, it correctly reads the saved file, but subsequent reads of the same file (even after the file has changed) result in the original image displaying.

As best as I can tell, if you run the following line:
local photofromfile = display.newImage( 'screenshot.png',system.DocumentsDirectory,100,100)

Then overwrite the image named 'screenshot.png' with a new image (through code in your app)

Then run the following line:
local photofromfileagain = display.newImage( 'screenshot.png',system.DocumentsDirectory,100,100)

The image that is read will be the same as the first, and will not reflect the changes you made to the screenshot.png file.

Re-launch the app, and the newest changes will appear the first time you read the file, but subsequent changes will not appear until app relaunch.

I have sample code if that would help.

Any ideas? Any suggestions on how to nuke a cached image?

uid: 4418 topic_id: 415 reply_id: 300415

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 22 posts
  • Corona SDK

If anyone is interested, or searching on os.rename, I finally fixed my last known bug by renaming my file to a random image name, reading it, then changing it back:

local rand = math.random(1,9999)
local tempChange = os.rename(system.pathForFile( 'userImage.png', system.DocumentsDirectory ),system.pathForFile( 'userImage'..rand..'.png', system.DocumentsDirectory ))
local myimage = display.newImage( "userImage"..rand..".png",system.DocumentsDirectory)
tempChange = os.rename(system.pathForFile( 'userImage'..rand..'.png', system.DocumentsDirectory ),system.pathForFile( 'userImage.png', system.DocumentsDirectory ))

Hope this helps someone.
uid: 4418 topic_id: 415 reply_id: 818