display.newImage and display.newImageRect are broken?

I’m praying that I’ve made a dumb mistake here and that someone can hit me aside the head and remind me about my occasional stupidity, but I’m completely stumped as to why this code doesn’t work. I’ve even tried to delay the loading of the saved file, but had no success. So, any help is much appreciated.

local img = display.newText("TEST",0,0,native.systemFontBold,50) -- create text object local w=img.width; local h=img.height -- save the object's width and height display.save(img,{filename="text.png"}) -- this saves the file properly - verified display.remove(img);img=nil -- remove the original object local obj=display.newImageRect("text.png",w,h) -- why is this object nil? print(tostring(obj)) -- this line prints "nil"

When you save the file it goes into the DocumentsDirectory by default. If you don’t specify a directory when loading a file, it assumes you mean the ResourcesDirectory. This should do the trick:

[lua]

local obj=display.newImageRect(“text.png”,system.DocumentsDirectory, w,h)

[/lua]

If you’re planning on submitting this to Apple for iOS, then I would recommend saving the files to system.TemporaryDirectory or system.CachesDirectory so they won’t get backed up to iCloud.  Obviously if this is a creation the user wants to create, system.DocumentsDirectory may be the right place, but if I’m following your project, you’re making temporary textures and you probably don’t want those polluting their system.DocumentsDirectory.

Rob

When you save the file it goes into the DocumentsDirectory by default. If you don’t specify a directory when loading a file, it assumes you mean the ResourcesDirectory. This should do the trick:

[lua]

local obj=display.newImageRect(“text.png”,system.DocumentsDirectory, w,h)

[/lua]

If you’re planning on submitting this to Apple for iOS, then I would recommend saving the files to system.TemporaryDirectory or system.CachesDirectory so they won’t get backed up to iCloud.  Obviously if this is a creation the user wants to create, system.DocumentsDirectory may be the right place, but if I’m following your project, you’re making temporary textures and you probably don’t want those polluting their system.DocumentsDirectory.

Rob