The game crashes on the phone, but everything is fine in Corona Simulator
local function preloadImage(fileDirectory, fileName, tableToInsert)
local texture = graphics.newTexture({
type = "image",
filename = string.format("%s/%s", fileDirectory, fileName),
baseDir = system.ResourceDirectory
})
texture:preload()
tableToInsert[fileName] = texture
end
local lfs = require("lfs")
for _,value in ipairs(toLoad.character) do
local oldPath = string.format("%s%s", texturesFolder, value)
local path = system.pathForFile(oldPath, system.ResourceDirectory)
loaded.character[value] = {}
local array = loaded.character[value]
for file in lfs.dir(path) do
if string.find(file, ".png") then
preloadImage(oldPath, file, array)
end
end
end