Problem with storyboard and writing to disk

Is there a known problem with storyboard and storing images and audio?

I am writing an app that lets you save Images and audio in the Resources Directory. I am having problems with both. If I write a file in one scene and try to read it in another the corona simulator gives me a warning that the file is not there. I can see the file in the sandbox just fine. 

The problem only occurs when using display.save() or media.newRecording() to write the data to a file, it does not come about when I use object:write.

I have a simple example of the problem. Te saving code looks like:

[lua]function scene:enterScene( event )

    saveBtn.isVisible = true

    image.isVisible = true

    addimgGroup:insert(saveBtn)

    local i = 3

    display.save( image,“myImage”…i…".jpg", system.DocumentsDirectory )

end[/lua]

The reading code is (on another scene):

[lua]function scene:createScene( event )

    addphotoGroup = self.view

    local i =3

    local imagePath =  system.pathForFile( “myImage”…i…".jpg", system.DocumentsDirectory ) 

    local image = display.newImageRect(imagePath, 864, 648)

    image.isVisible = false

    addphotoGroup:insert(image) 

end[/lua]

Any help will be more than appreciated.

Without knowing more about the flow of your program and if you are purging or removing scenes when they are not in use, the first thing that comes to mind is that storyboard caches scenes once created unless you are doing something to actively remove the scene.  So if you’re coming to the scene that reads the data after it’s been created once, then that code won’t be executed a second time.

Other than that, i don’t know if you have any data you’re needing to pass around to identify things.

Rob

I am including the whole code I created to test for the problem. it is not too long.

main.lua:

[lua]local storyboard = require( “storyboard” )

display.setStatusBar(display.HiddenStatusBar)

storyboard.gotoScene( “addimg”)[/lua]

addimg.lua:

[lua]local widget = require “widget”

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

local  _X = display.viewableContentWidth;  _Y = display.viewableContentHeight

local saveBtn, image

local function onSaveBtnRelease()

    storyboard.removeScene(“addphoto”)

    storyboard.gotoScene(“addphoto”, “fromRight”)

end

function scene:createScene( event )

    addimgGroup = self.view

    saveBtn = widget.newButton{

        defaultFile=“Save.png”,

        overFile=“Saveovr.png”,

        width=120, height=120,

        onRelease = onSaveBtnRelease    – event listener function

    }

    saveBtn.x =_X * 0.5

    saveBtn.y = _Y * 0.5

    saveBtn.isVisible = false

    addimgGroup:insert(saveBtn)

    image = display.newImageRect(“maze01.jpg”,  400, 300)

    image.isVisible = false

    addimgGroup:insert(saveBtn)

end

function scene:enterScene( event )

    saveBtn.isVisible = true

    image.isVisible = true

    addimgGroup:insert(saveBtn)

    local i = 3

    display.save( image,“myImage”…i…".jpg", system.DocumentsDirectory )

end

function scene:exitScene( event )

    display.remove (saveBtn)

    display.remove (image)

    saveBtn = nil

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene )

end

function scene:destroyScene( event )

    display.remove (saveBtn)

    display.remove (image)

    saveBtn = nil

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene)     

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene[/lua]

addphoto.lua:

[lua]local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

function scene:createScene( event )

    addphotoGroup = self.view

    local i =3

    local imagePath =  system.pathForFile( “myImage”…i…".jpg", system.DocumentsDirectory ) 

    local image = display.newImageRect(imagePath, 864, 648)

    image.isVisible = false

    addphotoGroup:insert(image) 

end

function scene:enterScene( event )

    image.isVisible = true

end

function scene:exitScene( event )

    display.remove (image)    

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene )

end

function scene:destroyScene( event )

    display.remove (image)    

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene)     

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene[/lua]

Thank you.

Without knowing more about the flow of your program and if you are purging or removing scenes when they are not in use, the first thing that comes to mind is that storyboard caches scenes once created unless you are doing something to actively remove the scene.  So if you’re coming to the scene that reads the data after it’s been created once, then that code won’t be executed a second time.

Other than that, i don’t know if you have any data you’re needing to pass around to identify things.

Rob

I am including the whole code I created to test for the problem. it is not too long.

main.lua:

[lua]local storyboard = require( “storyboard” )

display.setStatusBar(display.HiddenStatusBar)

storyboard.gotoScene( “addimg”)[/lua]

addimg.lua:

[lua]local widget = require “widget”

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

local  _X = display.viewableContentWidth;  _Y = display.viewableContentHeight

local saveBtn, image

local function onSaveBtnRelease()

    storyboard.removeScene(“addphoto”)

    storyboard.gotoScene(“addphoto”, “fromRight”)

end

function scene:createScene( event )

    addimgGroup = self.view

    saveBtn = widget.newButton{

        defaultFile=“Save.png”,

        overFile=“Saveovr.png”,

        width=120, height=120,

        onRelease = onSaveBtnRelease    – event listener function

    }

    saveBtn.x =_X * 0.5

    saveBtn.y = _Y * 0.5

    saveBtn.isVisible = false

    addimgGroup:insert(saveBtn)

    image = display.newImageRect(“maze01.jpg”,  400, 300)

    image.isVisible = false

    addimgGroup:insert(saveBtn)

end

function scene:enterScene( event )

    saveBtn.isVisible = true

    image.isVisible = true

    addimgGroup:insert(saveBtn)

    local i = 3

    display.save( image,“myImage”…i…".jpg", system.DocumentsDirectory )

end

function scene:exitScene( event )

    display.remove (saveBtn)

    display.remove (image)

    saveBtn = nil

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene )

end

function scene:destroyScene( event )

    display.remove (saveBtn)

    display.remove (image)

    saveBtn = nil

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene)     

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene[/lua]

addphoto.lua:

[lua]local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

function scene:createScene( event )

    addphotoGroup = self.view

    local i =3

    local imagePath =  system.pathForFile( “myImage”…i…".jpg", system.DocumentsDirectory ) 

    local image = display.newImageRect(imagePath, 864, 648)

    image.isVisible = false

    addphotoGroup:insert(image) 

end

function scene:enterScene( event )

    image.isVisible = true

end

function scene:exitScene( event )

    display.remove (image)    

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene )

end

function scene:destroyScene( event )

    display.remove (image)    

    image = nil

    scene:removeEventListener( “createScene”, scene )

    scene:removeEventListener( “enterScene”, scene )

    scene:removeEventListener( “exitScene”, scene )

    scene:removeEventListener( “destroyScene”, scene)     

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene[/lua]

Thank you.