[FIXED] Simulator Crashes on Taps?

I am trying to make a simple game similar to BreakOut Mania for iPad to practice with the Physics Engine before I make my own game. I added a global event listener to turn on physics when the user taps the screen anywhere, but when I run the app on an iPad in the simulator, the Corona Simulator “has quit unexpectedly” any time I try to click. Also, none of my blocks appear. My code is below. Originally, I also had a collision listener for the ball, but I deleted this and the problem of crashing persists. I am not sure if this is my fault or if it’s a bug with Corona. I have the latest version of Corona for a non-subscriber.

[code]
–Ball & Paddle
local midx=display.contentWidth/2
local ballRadius=20
local ball = display.newCircle(midx, display.contentHeight-35, ballRadius)
ball:setFillColor (0,200,200)
local paddleWidth=100
local paddle = display.newRoundedRect(midx-paddleWidth/2, display.contentHeight-10, paddleWidth, 10, 3)
paddle:setFillColor(100,100,100)

–Blocks
local blockWidth, blockHeight = 80, 50
local blockY = 50
local blockColor = 0,200,0
local blockStrokeColor = 255,255,255

local block1 = display.newRect(170,blockY, blockWidth, blockHeight)
block1:setFillColor(blockColor)
block1:setStrokeColor(blockStrokeColor)
local block2 = display.newRect(260,blockY, blockWidth, blockHeight)
block2:setFillColor(blockColor)
block2:setStrokeColor(blockStrokeColor)
local block3 = display.newRect(350,blockY, blockWidth, blockHeight)
block3:setFillColor(blockColor)
block3:setStrokeColor(blockStrokeColor)
local block4 = display.newRect(440,blockY, blockWidth, blockHeight)
block4:setFillColor(blockColor)
block4:setStrokeColor(blockStrokeColor)
local block5 = display.newRect(530,blockY, blockWidth, blockHeight)
block5:setFillColor(blockColor)
block5:setStrokeColor(blockStrokeColor)

function physicsSetUp()
physics = require “physics”
physics.setGravity(0, 9.8)
physics.setDrawMode(normal)
physics.start(true)
physics.addBody(ball, {density=0.5, bounce=0.7, radius=ballRadius})
ball.isBullet=true
physics.addBody(paddle, “static”)
physics.addBody(block1, “kinematic”)
physics.addBody(block2, “kinematic”)
physics.addBody(block3, “kinematic”)
physics.addBody(block4, “kinematic”)
physics.addBody(block5, “kinematic”)
end

Runtime:addEventListener(“tap”, physicsSetUp)
[/code] [import]uid: 23768 topic_id: 11911 reply_id: 311911[/import]

Your function says that every single time you tap you want to require physics, start physics (it’s already running after the first time) add all these bodies, etc.

Why are you doing this? And why is it tied to Runtime?

Peach [import]uid: 52491 topic_id: 11911 reply_id: 43539[/import]

I had originally set it up this way in order to start physics only after the user had tapped, so that the game wouldn’t start immediately after the app launched. I tried to remove the function and Runtime listener, replacing code after line 31 with this:

physics = require "physics"  
physics.setGravity(0, 9.8)  
physics.setDrawMode(normal)  
physics.start(true)  
physics.addBody(ball, {density=0.5, bounce=0.7, radius=ballRadius})  
 ball.isBullet=true  
physics.addBody(paddle, "static")  
physics.addBody(block1, "kinematic")  
physics.addBody(block2, "kinematic")  
physics.addBody(block3, "kinematic")  
physics.addBody(block4, "kinematic")  
physics.addBody(block5, "kinematic")  

But the Corona Simulator quit unexpectedly immediately after clicking open and choosing my main.lua file. Here is the error report:

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000000001923c
Crashed Thread: 0 Dispatch queue: com.apple.main-thread [import]uid: 23768 topic_id: 11911 reply_id: 43568[/import]

You changed the title to fixed; does that mean this fixed your problem?

If you wanted it to start on tap, you could have it do so - but remove the listener after ONE tap so it’s not trying to repeat itself any time the screen is tapped while the app is running.

Peach [import]uid: 52491 topic_id: 11911 reply_id: 44005[/import]