Okay I'm super confused about that one.
I coded a simple function to make an mirrored image table at run time, to save storage space on animations.
Now the issue is, if I later clear any image table made with this function (imagetable = nil) to get some memory back, the console crashes. I really can't figure that one out. Anyone has any idea?
Here's the function mirroring an image table:
function mirrorImageTable(imageTable)
local length = imageTable:getLength()
local mirroredImageTable = gfx.imagetable.new(length)
local firstImage = imageTable:getImage(1)
local xSize, ySize = firstImage:getSize() -- Gets image size from first image
for n = 1, length -- Mirrors frames
do
local image = gfx.image.new(xSize, ySize, gfx.kColorBlack)
local imageMask = gfx.image.new(xSize, ySize, gfx.kColorBlack)
gfx.pushContext(image)
gfx.setImageDrawMode(gfx.kDrawModeCopy) -- Normal copy mode
imageTable:drawImage(n, 0, 0, gfx.kImageFlippedX) -- Draws flipped image
gfx.popContext()
gfx.pushContext(imageMask)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite) -- Fillwhite mode for mask
imageTable:drawImage(n, 0, 0, gfx.kImageFlippedX) -- Draws mask flipped
gfx.popContext()
image:setMaskImage(imageMask) -- Assigns mask
mirroredImageTable:setImage(n, image) -- Sets mirrored image with mask
end
return mirroredImageTable
end
I was able to reproduce the crash with your code. It seems like an SDK bug to me.
Here is a version of the function that seems to work and doesn't crash when the memory is freed later
function mirrorImageTable(imageTable)
local length = imageTable:getLength()
local mirroredImageTable = gfx.imagetable.new(length)
local firstImage = imageTable:getImage(1)
local xSize, ySize = firstImage:getSize() -- Gets image size from first image
for n = 1, length -- Mirrors frames
do
local image = gfx.image.new(xSize, ySize, gfx.kColorClear)
gfx.pushContext(image)
gfx.setImageDrawMode(gfx.kDrawModeCopy) -- Normal copy mode
imageTable:drawImage(n, 0, 0, gfx.kImageFlippedX) -- Draws flipped image
gfx.popContext()
gfx.pushContext(image:getMaskImage())
gfx.setImageDrawMode(gfx.kDrawModeFillWhite) -- Fillwhite mode for mask
imageTable:drawImage(n, 0, 0, gfx.kImageFlippedX) -- Draws mask flipped
gfx.popContext()
mirroredImageTable:setImage(n, image) -- Sets mirrored image with mask
end
return mirroredImageTable
end
That’s interesting! Thank you for that. So the difference seems that you’re setting up the image with color clear, and you get the mask from the image, instead of setting a new image as mask. Should this be moved to SDK bugs then? I can’t quite figure why this new code works.