Spritesheet:dispose() immediately after calling display group's removeSelf() with nested sprite instance triggers error.

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]

…or just try it the other way round: first dispose the sheet, then remove the object.

Sheet:dispose()
Obj:removeSelf() [import]uid: 10504 topic_id: 12351 reply_id: 65655[/import]

There are scenarios where I must be able to call removeSelf on the container display group in advance of a sheet dispose. And even the workaround I posted is a hassle which causes race conditions.

I wish Ansca would fix this bug.

I had forgotten I filed this bug already. I was about to file it again. It’s quite frustrating. [import]uid: 27183 topic_id: 12351 reply_id: 65677[/import]

Hey, Don, I’ve come across the very same race condition bug. It does not seem to crash my game (and it does not seem to have any negative effect to the game, or at least it seems okay for now), but it certainly is annoying.

I wonder if this bug can cause a real problem down the road. It would be really nice to see it eradicated somehow.

Naomi [import]uid: 67217 topic_id: 12351 reply_id: 65830[/import]