CRASH - EXC_BAD_ACCESS when creating a new level

This is my game.lua file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local Level = require("level")
 
local currentLevel;
 
function new()
        
        local obj = display.newGroup();
        currentLevel = Level.new(1, obj); --this level creation works fine
        
        function obj:newLevel(e)
                local newLevel = Level.new(1, obj); --this level creation crashes
        end
        
        function obj:replay() --this gets called by the level
                currentLevel:destroy(); 
                
                timer.performWithDelay ( 1000, obj.newLevel, 1 ); --I don't think I should need to delay the creation of a new level, but the crash happens with or without the delay
        end
        
        return obj;
        
end

Try do to currentLevel = nil after currentLevel:destroy(); - not really sure, just an idea

Actually it turned out to be a problem with starting and stopping the physics engine in the wrong places. Since I stop the physics engine when a level gets destroyed, I had to start it whenever a new level is created.

views:1287 update:2011/10/1 9:04:19
corona forums © 2003-2011