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()

1
2
3
4
5
6
7
8
9
10
11
12
13
 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

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,

?:)

try putting the variable part as local.
local part = display.newImage( image, posX + posOffsetX, posY + posOffsetY )

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

here's a complete example of the problem

http://dl.dropbox.com/u/19981189/test1.zip

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

Have you tried :

1
2
3
if part.removeSelf then
    part:removeSelf()
end

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

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

Here's the section I modified...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
            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

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

views:1561 update:2011/10/4 8:06:35
corona forums © 2003-2011