Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
My game using Box2D is hell crashy — Gideros Forum

My game using Box2D is hell crashy

edited February 2014 in General questions
I am making a game where you have a set of scales, and must put the same weight on both sides.

This is my update code:

local function worldUpdate( event )
world:step(1/60, 8, 3);
updatePhysicsObject(barSpr);
updatePhysicsObject(supportSpr);
updatePhysicsObject(leftScaleSpr);
updatePhysicsObject(rightScaleSpr);
for ix, el in pairs(fruits) do
updatePhysicsObject(el);
end

local rotation = math.deg(barSpr.body:getAngle());
if rotation < 0 then rotation = -rotation end;
barSpr.body:setAngularDamping(25 - rotation*0.5);

if wait > 0 then
wait = wait - 1;
return;
end

if rotation < 2 then
print("getting angular velocity", debug.getinfo(1).currentline);
local angularVelocity = barSpr.body:getAngularVelocity();
if angularVelocity < 0 then angularVelocity = -angularVelocity end
if angularVelocity < 0.15 then
levelNumber = levelNumber + 1;
if levelNumber > maxLevelNumber then
return;
end
print("calling delete all fruits", debug.getinfo(1).currentline);
deleteAllFruits();
loadNewLevel();
wait = 100;
end
end
end


updatePysicsOBject purpose only is set the sprite to the body.
loadNewLevel is too long and complex to paste here, but basically it spawn stuff.

now, the curious part is the deleteAllFruits code:

local function deleteAllFruits()
world:clearForces();
local counter=0;
for ix, el in pairs(fruits) do
if not el.body then
print("for some reason a fruit is missing its body", ix);
end
world:destroyBody(el.body);
el:removeFromParent();
el = nil;
fruits[ix] = nil;
counter = counter + 1;
end
print("destroyed " .. counter .. " fruits")
end

Originally the "clearForces()" was not present.

When I comment out the "destroyBody()" the game works as intended, except leaves behind the physics of the last level...
If I leave the "destroyBody()" working, the game crashes when you win twice. (the first win works fine).
Later I experimented adding the "clearForces()" now it crashes when you win 5 or 6 times (don't remember exactly).


I am not sure of what to do now, and by "crash" I mean "crash", Gideros Player gets killed by Windows, no error message.

Note this game was made before in Corona SDK, and worked fine there, the code on Gideros is mostly a copy and paste with the changes needed on different API parts. (in fact if you wish, you can play the Corona SDK version, it is on Google Play, it is a minigame on the second map of this game: https://play.google.com/store/apps/details?id=com.kidoteca.nonoamazonia.beta )
I make games for children: http://www.kidoteca.com
«1

Comments

Sign In or Register to comment.