Bugged as (Case 6848).
If you call spriteInstance:removeSelf(), then spriteSheet:dispose() no error occurs. But if the spriteInstance is inside a displayGroup and the displayGroup:removeSelf() is called then spriteSheet:dispose() you get this error:
ERROR: Attempt to remove an object that’s already been removed from the stage or whose parent/ancestor group has already been removed.
The workaround shown below is to put the dispose call into a timer callback.
– code below can be put into the HorseAnimation sample
require “sprite”
display.setStatusBar(display.HiddenStatusBar)
local dg = display.newGroup()
local uma = sprite.newSpriteSheetFromData( “uma.png”, require(“uma”).getSpriteSheetData() )
local spriteSet = sprite.newSpriteSet(uma,1,8)
sprite.add(spriteSet,“uma”,1,8,1000,0)
local spriteInstance = sprite.newSprite(spriteSet)
dg:insert(spriteInstance)
spriteInstance:setReferencePoint(display.BottomRightReferencePoint)
spriteInstance.x = 480
spriteInstance.y = 320
spriteInstance:prepare(“uma”)
spriteInstance:play()
dg:removeSelf()
uma:dispose()
– calling this instead of uma:dispose above is safe
–timer.performWithDelay(0, function() uma:dispose() end)
[import]uid: 27183 topic_id: 12351 reply_id: 312351[/import]