Spriteloq and Director crash?

Has anybody been using Spriteloq with Director Class? I am using Director 1.3 in my project and experienced the simulator crashing when I tried to change the scene.

This will crash the simulator:

1
2
3
4
5
6
local function goBackToMenu ( event )
        spriteFactory1:dispose()
        spriteFactory2:dispose()
        spriteFactory3:dispose()
        director:changeScene("menu")
end

I use Spriteloq and Director Class, and I use timer.performWithDelay. I'd set it to timer.performWithDelay(1, runDirector) -- as far as I know, we would need the timer to make this work.

Also, you might want to take a look at http://www.loqheart.com/spriteloq/apidocs/files/loq_sprite-lua.html#SpriteFactory.dispose

If there are other ways to make this work, I'd like to know too.

@ask

I originally tried
timer.performWithDelay(100, runDirector)
but still crashed.

Setting it to 200 did the trick

I guess I could try 1 but if 100 doesn't work...

Have you done this?

@ChunkyApps, I do this in every single level of my game.

I have one spriteFactory in each level, and I create various instances of SpriteGroup. When I change scene, I use something like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
        -- going back to menu.lua from level1.lua
        function changeScene(event)
                local function launchWithDelay()
                        spriteFactory:dispose();
                        spriteFactory = nil;
                        director:changeScene("menu", "flip"); -- changing scene to menu.lua
                        unrequire("level1"); -- unrequiring level1.lua
                end
                -- here I add number of functions that need to be triggered before the
                -- scene changes (like stopping moving parts, etc. and then the timer comes after 
                -- the necessary functions , etc.
                timerStash.newTimer = timer.performWithDelay(1, launchWithDelay);
        end     

I'm a bit confused on this:

you call the dispose() method along with the director:changeScene() method at the same time (in launchWithDelay() function)
what is the timer.performWithDelay actually doing then?

I thought you call dispose() then wait a millisecond to changeScene()

Here it seems you are waiting a millisecond then calling dispose() and changeScene()

I'll try to go back and make it one spriteFactory. Maybe that is my issue.

Maybe because I didn't include spriteFactory = nil ?

@ask

Also, do you add your sprites to Director's localGroup?

Woops, about the spriteFactory:dispose() and spriteFactory = nil that appear inside the launchWithDelay function -- that wasn't the very best example, was it. Sorry about that.

I do usually have the spriteFactory:dispose() and spriteFactory = nil right above the timer (not inside the timer). That said, in some situations, I do need them inside the timer to make it work properly for certain types of scene change I do.

Not including spriteFactory = nil wound't cause a crash.

About adding sprites to Director's localGroup -- I don't add spriteFactory to Director's localGroup, because spriteFactory isn't display object. I add SpriteGroup instances that I create using spriteFactory:newSpriteGroup to the localGroup, because SpriteGroup instances are display object -- or at least that's what I deduced, and it seems to work as expected.

okay so I brought it down to one spriteFactory, added the spriteFactory = nil, and added the unrequire.

Simulator still crashes if I use anything less than 101ms (100ms crashes and 101ms works)

oh well, it works... that's the main thing

Maybe you have something else going on that needs taken care of before you change the scene. It's probably nothing to do with the spriteFactory or the SpriteGroup.

But yes, I totally agree. If it works, all is well.

views:1602 update:2011/10/12 9:17:43
corona forums © 2003-2011