segmentation fault when using the bridge sample app and removeAll()

Hi guys,

I’m having this error only when running my app on my ios device:
Application ‘segmentation’ exited abnormally with signal 11: Segmentation fault: 11

Basically what I do is take the code from the Bridge example (a bridge with joints) and insert it into scene1. Then I Add a touch listener on an object to change to scene2.

In scene2 right after scene:enterScene I call storyboard.removeAll() and boom! my app crashes and quits immediately leaving a segmentation fault. It’s frustrating because on the simulator runs perfectly fine.

I appreciate your help a lot, I even removed the touch joint listeners from the Bridge example thinking it had something to do with that. but keeps crashing every time.

thanks

[code]

– scene1.lua

local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local physics = require “physics”
physics.start(); physics.pause()


– forward declarations and other locals
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5
local grass

local function changeE(event)
storyboard.gotoScene(“scene2”)
end

– BEGINNING OF YOUR IMPLEMENTATION

– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view

– create a grey rectangle as the backdrop
local background = display.newRect( 0, 0, screenW, screenH )
background:setFillColor( 128 )

– create a grass object and add physics (with custom shape)
grass = display.newImageRect( “grass.png”, screenW, 82 )
grass:setReferencePoint( display.BottomLeftReferencePoint )
grass.x, grass.y = 0, display.contentHeight

– define a shape that’s slightly shorter than image bounds (set draw mode to “hybrid” or “debug” to see)
local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
physics.addBody( grass, “static”, { friction=0.3, shape=grassShape } )
grass:addEventListener(“touch”,changeE)

– all display objects must be inserted into group
group:insert( background )
group:insert( grass)

end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view

physics.start()
—code from the bridge example
local pole1 = display.newImage( “bamboo.png” )
pole1.x = 50; pole1.y = 250; pole1.rotation = -12
physics.addBody( pole1, “static”, { friction=0.5 } )

local pole2 = display.newImage( “bamboo.png” )
pole2.x = 430; pole2.y = 250; pole2.rotation = 12
physics.addBody( pole2, “static”, { friction=0.5 } )

group:insert(pole1)
group:insert(pole2)

local board = {}
local joint = {}

for j = 1,16 do
board[j] = display.newImage( “board.png” )
group:insert(board[j])
board[j].x = 20 + (j*26)
board[j].y = 150

physics.addBody( board[j], { density=2, friction=0.3, bounce=0.3 } )

– damping the board motion increases the “tension” in the bridge
board[j].angularDamping = 5000
board[j].linearDamping = 0.7

– create joints between boards
if (j > 1) then
prevLink = board[j-1] – each board is joined with the one before it
else
prevLink = pole1 – first board is joined to left pole
end
joint[j] = physics.newJoint( “pivot”, prevLink, board[j], 6+(j*26), 150 )

end

– join final board to right pole
joint[#joint + 1] = physics.newJoint( “pivot”, board[16], pole2, 6+(17*26), 150 )

end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
grass:removeEventListener(“touch”,changeE)

physics.stop()

end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view

package.loaded[physics] = nil
physics = nil
end

[/code] [import]uid: 74667 topic_id: 35324 reply_id: 335324[/import]

so I found what was causing the error… calling physics.stop() on scene:exitScene( event ).
I removed that and it works just fine. [import]uid: 74667 topic_id: 35324 reply_id: 140459[/import]

so I found what was causing the error… calling physics.stop() on scene:exitScene( event ).
I removed that and it works just fine. [import]uid: 74667 topic_id: 35324 reply_id: 140459[/import]

Oh boy, am i glad for finding this post? It saved me from a huge headache. :slight_smile: I have same problem. The thing is - I am using storyboard. There are 4 scenes. 3 of them have physics with same structure - physics.start() in scene:enterScene(event) and physics.stop() in scene:exitScene(event). There are no errors in Corona Simulator. But on device only one scene causing crash. Removing physics.stop() from scene:exitScene(event) in this scene solved the problem as described above. I can’t see any major difference between the scenes. So the question is why this strange behavior. 

Ok, I figured this out while I was eating dinner. Food solves problems. ;) 

Before you call physics.stop() you actually need to remove all bodies and joints. That is the difference in my scenes. One scene has joints. I was only removing bodies before. So now when I remove joints as well I can call physics.stop() in scene:exitScene(event). No crashes. 

If you have time and will you can try to modify the bridge sample and see if it helps.  

am having similar problem on android, where it shows up in logcat as “signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)”

coming from a play scene with touch-joint-drag-physics and its event handler, transition to an awards scene, then back to play scene, then crash during re-init-ing the game in willEnterScene.  (maybe 10% of the time)

(complicated by the fact that i don’t fully purge the play scene, just wipe level-specific things and recreate them, starting/stopping physics in between) 

i haven’t fully tracked it yet, but problem seems to be on reestablishing physics connection to my “drag” object it seems like physics still has a reference to an old touch joint lingering around.   (but attempting to do dragthing.touchJoint:removeSelf() at the END of the scene simply cause it to crash 10% there instead)

i do remove the listener before trying to remove the joint, but am wondering if i have a threading -type issue, where maybe an event tries to show up just after i’ve started taking things apart.  so i can’t properly remove the joint at end, then it comes back to haunt me at restart.  i don’t know, just talking out loud, will monitor this thread if anyone else has any further insight.

Oh boy, am i glad for finding this post? It saved me from a huge headache. :slight_smile: I have same problem. The thing is - I am using storyboard. There are 4 scenes. 3 of them have physics with same structure - physics.start() in scene:enterScene(event) and physics.stop() in scene:exitScene(event). There are no errors in Corona Simulator. But on device only one scene causing crash. Removing physics.stop() from scene:exitScene(event) in this scene solved the problem as described above. I can’t see any major difference between the scenes. So the question is why this strange behavior. 

Ok, I figured this out while I was eating dinner. Food solves problems. ;) 

Before you call physics.stop() you actually need to remove all bodies and joints. That is the difference in my scenes. One scene has joints. I was only removing bodies before. So now when I remove joints as well I can call physics.stop() in scene:exitScene(event). No crashes. 

If you have time and will you can try to modify the bridge sample and see if it helps.  

am having similar problem on android, where it shows up in logcat as “signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)”

coming from a play scene with touch-joint-drag-physics and its event handler, transition to an awards scene, then back to play scene, then crash during re-init-ing the game in willEnterScene.  (maybe 10% of the time)

(complicated by the fact that i don’t fully purge the play scene, just wipe level-specific things and recreate them, starting/stopping physics in between) 

i haven’t fully tracked it yet, but problem seems to be on reestablishing physics connection to my “drag” object it seems like physics still has a reference to an old touch joint lingering around.   (but attempting to do dragthing.touchJoint:removeSelf() at the END of the scene simply cause it to crash 10% there instead)

i do remove the listener before trying to remove the joint, but am wondering if i have a threading -type issue, where maybe an event tries to show up just after i’ve started taking things apart.  so i can’t properly remove the joint at end, then it comes back to haunt me at restart.  i don’t know, just talking out loud, will monitor this thread if anyone else has any further insight.