Runtime Error When Switching Scenes? (Video and Screenshots)

While in the process of switching scenes using storyboard I receive the following runtime error ( see attachments )

Here is a link to the youtube video demonstrating the problem:

https://www.youtube.com/watch?v=zU6IBxqGdIg&feature=youtu.be

As you can see, the error doesn’t happen necessarily every time, I had to play it a couple times before it happened. The error is when the screen goes black. Also, I’d like to point out that this error is more common on “insane” mode than on “easy” mode. ( Insane mode has a lot more balls spawning than easy mode) I’d say It happens about 1/4 of the time. This doesn’t only occur when reloading the scene, It also occurs when going to the main menu from that scene. Here is all my code that includes anything that references the runtime module:

[lua]

local function onAccelerate( event )

if player.x >= display.contentWidth and event.yGravity < 0 then

print(“Player not move: x is over screen”)

elseif player.x <= 0 and event.yGravity > 0 then

print(“Player not move: x is below screen”)

else

    player.x = player.x - (event.yGravity*15)

end

end

[/lua]

[lua]

local function addScoreRepeat()

if gameMode == “practice” then

print(“practice”)

else

if deathCount == nil then

gameScore = gameScore + 2

gameScoreAdd = math.round(gameScore)

display.remove(scoreTxt)

scoreTxt = display.newText( gameScoreAdd, 0, 0, native.systemFont, 18 )

scoreTxt:setReferencePoint(display.TopRightReferencePoint)

scoreTxt.x = scoreX+80

scoreTxt.y = screenTop + 5

group:insert(scoreTxt)

end

end

end

[/lua]

[lua]

function scene:enterScene( event )

local group = self.view

system.setAccelerometerInterval( 60 )

Runtime:addEventListener( “enterFrame”, addScoreRepeat )

Runtime:addEventListener( “accelerometer”, onAccelerate )

end

[/lua]

[lua]

function scene:exitScene( event )

local group = self.view

for t = #spawnTimers, 1, -1 do

    timer.cancel( spawnTimers[t] )

    spawnTimers[t] = nil

end

–for m = #deathDelete, 1 -1 do

– display.remove(deathDelete[m])

– end

– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)

deathCount = nil

Runtime:removeEventListener( “enterFrame”, addScoreRepeat )

Runtime:removeEventListener( “accelerometer”, onAccelerate )

storyboard.removeAll ( )

end

[/lua]

This extra code my be unnecessary for you, but I though I’d include it anyway:

[lua]

local function spawnBall()

local size = mRandom(14,25)/100

local moreBallHeight = 0

if size > 22 then

local moreBallHeight = mRandom(19,25)

end

local ball = display.newImageRect(“game_ballred.png”,720,720)

ballDelete[#ballDelete+1] = ball

if deathScreen == not nil then

deathScreen:toFront()

end

ball.type = “red”

–ball:setReferencePoint( display.BottomCenterReferencePoint )

ball:scale(size, size)

local minus = (1-size) * 247

local ball_box = 247 - minus

local ballX = mRandom(65, 110) * -1

local ballY = mRandom(10,50) - moreBallHeight

ball.x = ballX

ball.y = ballY-ball_box+40

local ball_bounce = mRandom(96,98)/100

physics.addBody(ball, { radius = ball.contentWidth/2, bounce = ball_bounce, filter = collisionFilter } )

if gameMode == “practice” then

xForce = mRandom(24,30)/100

elseif gameMode == “easy” then

xForce = mRandom(22,26)/100

elseif gameMode == “medium” then

xForce = mRandom(24,30)/100

elseif gameMode == “hard” then

xForce = mRandom(30,36)/100

elseif gameMode == “insane” then

xForce = mRandom(35,40)/100

end


–xForce = mRandom(24,30)/100

yForce = mRandom(.28,.37)

ball:applyLinearImpulse( xForce, yForce, ball.x, ball.y )

ball:toBack()

bg:toBack()

if gameMode == “practice” then

backBtn2:toFront()

end

group:insert(ball)

local spawnTimeYellow = mRandom(100,1000)

local randomYellow = mRandom(1,3)

if randomYellow == 1 then

timer.performWithDelay(spawnTimeYellow,spawnBallYellow)

end

local spawnTimeBlue = mRandom(100,1000)

local randomBlue = mRandom(1,70)

if randomBlue == 1 then

timer.performWithDelay(spawnTimeBlue,spawnBallBlue)

end

local spawnTimeGreen = mRandom(100,1000)

local randomGreen = mRandom(1,42)

if randomGreen == 1 then

timer.performWithDelay(spawnTimeGreen,spawnBallGreen)

end

local spawnTimeNuke = mRandom(100,1000)

local randomNuke = mRandom(1,50)

if randomNuke == 1 then

timer.performWithDelay(spawnTimeNuke,spawnBallNuke)

end

local spawnTimeOrange = mRandom(100,1000)

local randomOrange = mRandom(1,8)

if randomOrange == 1 then

timer.performWithDelay(spawnTimeOrange,spawnBallOrange)

end

if gameMode == “practice” then

spawnTimeBall = mRandom(1200,1300)

elseif gameMode == “easy” then

spawnTimeBall = mRandom(1400,1500)

elseif gameMode == “medium” then

spawnTimeBall = mRandom(1200,1300)

elseif gameMode == “hard” then

spawnTimeBall = mRandom(925,1025)

elseif gameMode == “insane” then

spawnTimeBall = mRandom(625,775)

end


–spawnTimeBall = mRandom(1200,1300)

local extraBall = mRandom(1,12)

if extraBall == 1 then

noSpawn = true

print( “EXTRA BALL HAS JUST SPAWNED”)

print(fasterBall)

spawnTimers[#spawnTimers+1] = timer.performWithDelay(spawnTimeBall/2-fasterBall, spawnBall)

end

if gameMode == “practice” then

fasterBall = 0

elseif gameMode == “easy” then

fasterBall = fasterBall +3

elseif gameMode == “medium” then

fasterBall = fasterBall +3.35

elseif gameMode == “hard” then

fasterBall = fasterBall +4

elseif gameMode == “insane” then

fasterBall = fasterBall +4.75

end


–fasterBall = fasterBall +3.3

–fasterBallAdd = math.round(fasterBall)

if noSpawn == false then

spawnTimers[#spawnTimers+1] = timer.performWithDelay(spawnTimeBall-fasterBall, spawnBall)

end

noSpawn = false

–250 10% 25

end

[/lua]

[lua]

function scene:createScene( event )

group = self.view

– CREATE display objects and add them to ‘group’ here.

for t = #ballList, 1, -1 do

    timer.cancel( ballList[t] )

    ballList[t] = nil

end

display.remove(_G.bgGroup)

_G.bgGroup = nil

storyboard.removeAll ( )

–displayBackground(group)

bg = display.newImageRect(“game_background.png”,2012,1403)

bg:addEventListener( “touch”, playerMove )

group:insert(bg)

if gameMode == “practice” then

print(“it is practice”)

else

scoreTxt = display.newText( “0”, 0, 0, native.systemFont, 18 )

scoreTxt:setReferencePoint(display.TopRightReferencePoint)

scoreTxt.x = scoreX+80

scoreTxt.y = screenTop + 5

group:insert(scoreTxt)

moneyTxt = display.newText( “0c”, 0, 0, native.systemFont, 18 )

moneyTxt:setReferencePoint(display.TopRightReferencePoint)

moneyTxt.x = scoreX+80

moneyTxt.y = screenTop + 32

group:insert(moneyTxt)

end

local ground2 = display.newImageRect(“game_ground.png”,4061,81)

ground2.y = display.contentHeight

ground2.x = ground2.x +2000

physics.addBody(ground2, “static”, { } )

group:insert(ground2)

local ground3 = display.newImageRect(“game_ground.png”,4061,81)

ground3.y = display.contentHeight

ground3.x = ground2.x -2000

physics.addBody(ground3, “static”, { } )

group:insert(ground3)

local ground = display.newImageRect(“game_ground.png”,4061,81)

ground.y = display.contentHeight-20

ground.x = ground.x -5

group:insert(ground)

wall = display.newRect(0,0,5, display.contentHeight)

wall.x = display.contentWidth + 150

wall.y = display.contentCenterY

wall.type = “wall”

physics.addBody(wall,“static”)

wall.collision = ballCollision

wall:addEventListener(“collision”, wall)

group:insert(wall)

player = display.newImageRect(“game_player.png”,67,67)

player.x = display.contentWidth - 25

player.y = ground2.y - 61

player:scale(.63,.63)

physics.addBody(player, “static”, { radius = 12 } )

player.collision = playerCollision

player:addEventListener(“collision”, player)

group:insert(player)

–player:addEventListener(

–[[

local ball = display.newImage(“game_ball.png”)

ball:scale(.1,.1)

physics.addBody(ball, { radius = 14 } )

group:insert(ball)

local ball2 = display.newImage(“game_ball.png”)

physics.addBody(ball2, { radius = 140 } )

group:insert(ball2)

]]

–local backBtn = makeTextButton(“Back”, screenLeft + 40, screenTop + 15, {listener=buttonHit, group=group})

–backBtn.gotoScene = “menu”

–14 / 10% , start 140

end

[/lua]

I’ve tried to make this post as descriptive as possible to describe my problem, if anyone needs to see more code or needs more information just ask. Thank you to anyone replies.

Can you post the contents of the debug window when the error occurs?

it is in attachments

Ah, must have missed that in your post.

I’d say the debug info is pretty self-explanatory. There is an error at line 679 of the play.lua file. Your best bet is to isolate what is happening at that line, and figuring our what is causing that error to happen. If it’s intermittent, and you’re referring to “regular” and “insane” modes of your game, I’d venture to guess that the objects aren’t being spawned and/or removed correctly.

I think I’ve solved the problem. I just made it so that every time I die I call a function that deletes all of the balls. The error must have been happening because of memory or something. Not the way I wanted it to happen but I guess if it works thats what ill do. Thank you for your response.

Alex is right.  On line 679 (which we have no idea what is live 679, you’re trying to call some object’s “insert” method.  However that object does not have an “insert” method.   The most common object that you would use “insert” with is putting things in a group or container.  The most likely reason a group would not have an insert method is if the group has been removed, overwritten or nilled out, which could happen if you’re changing scenes but your spawner is still running and you remove the scene.

In the simulators terminal/command window there will be a log of print messages and error messages.  When you get that error, there will be a stack trace that will show you more about who called what.  Since the message happened multiple times, it adds to the idea that it’s the spawner still running.

Rob

Can you post the contents of the debug window when the error occurs?

it is in attachments

Ah, must have missed that in your post.

I’d say the debug info is pretty self-explanatory. There is an error at line 679 of the play.lua file. Your best bet is to isolate what is happening at that line, and figuring our what is causing that error to happen. If it’s intermittent, and you’re referring to “regular” and “insane” modes of your game, I’d venture to guess that the objects aren’t being spawned and/or removed correctly.

I think I’ve solved the problem. I just made it so that every time I die I call a function that deletes all of the balls. The error must have been happening because of memory or something. Not the way I wanted it to happen but I guess if it works thats what ill do. Thank you for your response.

Alex is right.  On line 679 (which we have no idea what is live 679, you’re trying to call some object’s “insert” method.  However that object does not have an “insert” method.   The most common object that you would use “insert” with is putting things in a group or container.  The most likely reason a group would not have an insert method is if the group has been removed, overwritten or nilled out, which could happen if you’re changing scenes but your spawner is still running and you remove the scene.

In the simulators terminal/command window there will be a log of print messages and error messages.  When you get that error, there will be a stack trace that will show you more about who called what.  Since the message happened multiple times, it adds to the idea that it’s the spawner still running.

Rob