0
votes

So I just started learning how to use the Corona SDK to create games. Making an asteroid-field shooting type game, and came across this error when trying to play the game.

(I know there is almost an exact replica of this question, but it has 0 answers and the only comment does not apply to me.)

This is the full error + stack trace:

19:21:16.393  ERROR: Runtime error
19:21:16.393  C:\Users\Some User\Documents\Corona Projects\StarExplorer\game.lua:87: bad argument #-1 to 'newImageRect' (Proxy expected, got nil)
19:21:16.393  stack traceback:
19:21:16.393    [C]: in function 'newImageRect'
19:21:16.393    C:\Users\Some User\Documents\Corona Projects\StarExplorer\game.lua:87: in function '_listener'
19:21:16.393    ?: in function <?:167>
19:21:16.393    ?: in function <?:169>

Here is a hastebin of the game.lua, and here is a hastebin of the menu.lua class, which switches the scene from menu to game.

I can tell as much as line 87 is causing the issue, and that something is wrong with the arguments for newImageRect, but apart from that I have no clue.

The game runs and plays perfectly on first run, but attempting to replay it causes the error. The code which switches the scene in the menu file is on lines 13-17.

Any help is appreciated, sorry if I am being silly and missing something obvious.
Thanks!

EDIT: The error is caused when it attempts to remove the game.lua scene.

1
This error will happen when your any syntax value is in null in newImageRect.When move to another scene just call composer.removeHiidden().Can you post the game.lua line 87. - AndroidUser
local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 ) - Line 87, game.lua - Sulphate
Where created that objectSheet.In your code why u used 1, can you explain.i cannot get you.look at the syntax display.newImageRect( [parent,] filename, [baseDir,] width, height ) - AndroidUser
mainGroup is the parent (display group), objectSheet is the file(name), 1 is the index of the image I want (In this case it is the First Image, an Asteroid), 102 = width, 85 = height. Remember that this error is caused when the scene is removed. - Sulphate
Above code is in timer function. - AndroidUser

1 Answers

1
votes

You are calling createAsteroid with a timer.performDelay. So, you need to cancel this timer when game scene is destroyed or hidden.

asteroidSpawnTimer = timer.performWithDelay( asteroidSpawnTime, createAsteroid, 0 )

Try this:

function scene:hide( event )
--[[...]]--
if ( phase == "will" ) then
    timer.cancel( gameLoopTimer )
    timer.cancel( asteroidSpawnTimer ) -- cancel it
--[[...]]--