anyone see why i get an error with this

my app will loop though this code several time
but i get an error when if gets to part:removeSelf()

[blockcode]
part = display.newImage( image, posX + posOffsetX, posY + posOffsetY )
part:scale( imgSize, imgSize )
part.alpha = startAlpha
newDirX = part.x + dirX
newDirY = part.y + dirY

local transC = transition.to( part, { time = showTime - dirSpeed, delay = pauseTime, alpha = endAlpha, x = newDirX, y = newDirY, onComplete = function(event)
part:removeSelf()
transC = nil
end} )

partGroup:insert( part )
if layer then layer:insert( partGroup ) end
[/blockcode]

i tried changing it to this also to make sure the object was there

[blockcode]
if part then part:removeSelf() end
[/blockcode] [import]uid: 7911 topic_id: 14985 reply_id: 314985[/import]

you have not posted the key component of the code - The error that you get, but still you have mentioned the key component, the root to your issue.

You are calling this code several times, and the issue that you *definitely* will face is due to the fact
Your transition will spawn with a delay and last a time, after which the onComplete is run, which tries to remove the object. What happens is there are times when the transaction is waiting to be completed and the next object is created or the older object is supposed to be removed but the new object that is created is removed as the handle points to that and on completion it is nil:removeSelf() as the object has already been removed.

I hope you are understanding what I am saying here. if you ened to have several *parts* then have a factory function in your code that creates an all inclusive *part* that has its own touch and remove and transition, so that the errors that you mention are reduced.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14985 reply_id: 55322[/import]

try putting the variable part as local.
[lua]local part = display.newImage( image, posX + posOffsetX, posY + posOffsetY ) [/lua] [import]uid: 71210 topic_id: 14985 reply_id: 55323[/import]

thanks
@ren ill give that a try

@jay i also tried setting it up with part[plus] = display…
and increase the plus for each loop but that didnt work either
[import]uid: 7911 topic_id: 14985 reply_id: 55327[/import]

here’s a complete example of the problem

http://dl.dropbox.com/u/19981189/test1.zip [import]uid: 7911 topic_id: 14985 reply_id: 55328[/import]

second example
http://dl.dropbox.com/u/19981189/test2.zip [import]uid: 7911 topic_id: 14985 reply_id: 55330[/import]

if i remove line 55 for js.lua in example 2 the transition works but memory usage keeps increasing which is what i am trying to prevent [import]uid: 7911 topic_id: 14985 reply_id: 55332[/import]

Have you tried :

if part.removeSelf then part:removeSelf() end [import]uid: 84637 topic_id: 14985 reply_id: 55338[/import]

I’ve tried so much in past 2 weeks I couldn’t be sure but I’ll try as soon as I get back to the computer thanks [import]uid: 7911 topic_id: 14985 reply_id: 55339[/import]

I made 2 modifications to your js.lua file and got it to work…

Here’s the section I modified…

 if image == "circle" then  
 part[plus][multi] = display.newCircle( posX + posOffsetX, posY + posOffsetY, imgSize )  
 partGroup:insert( part[plus][multi] )  
  
 part[plus][multi].strokeWidth = stroke  
 part[plus][multi].alpha = startAlpha  
 part[plus][multi]:setStrokeColor( strokeRed, strokeGreen, strokeBlue )  
 part[plus][multi]:setFillColor( fillRed, fillGreen, fillBlue, fillAlpha )  
 newDirX = part[plus][multi].x + dirX  
 newDirY = part[plus][multi].y + dirY  
  
 local transA = transition.to( part[plus][multi], { time = showTime - dirSpeed, alpha = endAlpha, x = newDirX, y = newDirY, onComplete = function(event)  
 display.remove(part[plus][multi])  
 part[plus][multi] = nil  
 transA = nil  
 end} )  
  
 if layer then layer:insert( partGroup ) end  
  
 if partGroup.numChildren \> imgMaxCount then  
 repeat  
 partGroup:remove(1)  
 until partGroup.numChildren \< imgMaxCount/2  
 end  
 end  
  

The changes I made:

Notice line 3 above - I always like to add display objects into their group right away so I move this lie up

Notice line 13 above - I think you are running into conflicting operations removing display objects, by changing this to display.remove it will check to make sure it is not already been nil’d

The second bullet highlights a great practice by Beebe that I have shifted to in all my display object removals. Read this if you haven’t seen it yet: Corona SDK Memory Leak Prevention 101
Hope that helps, good luck!

–Croisened
[import]uid: 48203 topic_id: 14985 reply_id: 55404[/import]

thanks Croisened
i think this will work
it got rid of the error i was having now letting it run for awhile to see if memory usage is ok
i had to make adjustments to my main.lua file so very few object are removed before there life cycle and after a 3 minute run it looks good now testing for a 30 minute run [import]uid: 7911 topic_id: 14985 reply_id: 55419[/import]