Hello! I believe I've found a bug when changing skins in corona. Using the official runtime, i've tried to change goblin to goblingirl skin, by adding a simple timer, and
skeleton:setSkin("goblingirl"),
but it comes out with error message:
ERROR: Runtime error
spine-lua/Skin.lua:71: attempt to call a nil value
stack traceback:
spine-lua/Skin.lua:71: in function 'attachAll'
spine-lua/Skeleton.lua:416: in function 'setSkinByReference'
spine-lua/Skeleton.lua:410: in function 'setSkin'
main.lua:37: in function '_listener'
?: in function '?'
?: in function <?:190>
now, tracing back the problem, I found something strange in the function Skin:attachAll(skeleton, oldSkin) inside Skin.lua file.
first one the 71-st row:
for key, value in dictionary do
shouldn't this be
in ipairs
?
secondly, there is an incrementing index in the beginning of the function
local slotIndex = 0
which increments
oldSkin.attachments[slotIndex]
but as far as i know lua tables start from index 1, not 0?
Anyways, even when i changed the index to 1 as well as the loop to ipairs, it still did not work.
Am I doing something wrong? Help...
UPDATE:
Hi, I think I managed to solve my own problem. The original code in Skin.lua is as follows, from row 65:
function Skin:attachAll(skeleton, oldSkin)
local slotIndex = 0
for i, slot in ipairs(skeleton.slots) do
local slotAttachment = slot.attachment
if slotAttachment and slotIndex <= #oldSkin.attachments then
local dictionary = oldSkin.attachments[slotIndex]
for key, value in dictionary do
local skinAttachment = value
if slotAttachment == skinAttachment then
local attachment = getAttachment(slotIndex, key)
if attachment then slot.attachment = attachment end
break
end
end
end
slotIndex = slotIndex + 1
end
end
I've changed it to:
function Skin:attachAll(skeleton, oldSkin)
local slotIndex = 1
---
0
for i, slot in ipairs(skeleton.slots) do
local slotAttachment = slot.attachment
if slotAttachment and slotIndex <= #oldSkin.attachments then
local dictionary = oldSkin.attachments[slotIndex]
if dictionary ~= nil then
---
this checks if dictionary exists
for key, value in ipairs(dictionary) do
local skinAttachment = value
if slotAttachment == skinAttachment then
local attachment = getAttachment(slotIndex, key)
if attachment then slot.attachment = attachment end
break
end
end
end
end
slotIndex = slotIndex + 1
end
end
and for my project at least everything runs fine with skin changes on the fly. But I think this (or similar) solution should be implemented in to the official lua runtime, because, as it is now it simply doesn't seem to work, or rather it's just wrong lua code. Thanks! :angel: