I think i have nail it down to where it is causing it. But still I have no idea where it is happening because all print functions work (even at the last line of scene:createScene).
I am using 1137, the latest stable build provided by corona sdk.
Issue to reproduce:
-
Under game.lua line 37 to 39, if i comment this out, there will be no crash that pops up.
-
Putting the issue into the fishclass.lua itself.
-
However if I didn’t comment line 37 to 39 under game.lua, you will still see “Scene fully created!” message at line 66 under game.lua even when the error pops up. Meaning that all creation ran successfully and it reaches the end of createScene
Here is the code:
main.lua
local sb = require "storyboard" local function main() sb.gotoScene( "assets.script.game" ) end main()
game.lua
-------------------- -- REQUIRE -------------------- -- STORYBOARD local sb = require "storyboard" local sceneGame = sb.newScene() sb.purgeOnSceneChange = true -- FISH CLASS local fish = require "assets.script.fishclass" -- SERIALIZER local sz = require "assets.script.jsonserializer" -------------------- -- GAME FUNCTIONS -------------------- -- GAME LOOP local function gameLoop() if ( sb.gameActive ) then -- NYI end end -- local function initGame() print( "Init game..." ) -- Create Display Group sb.backGroup = display.newGroup() sb.midGroup = display.newGroup() sb.frontGroup = display.newGroup() -- Create player fish sb.pet = nil local fishData = sz.loadData( "assets/data/testfish.json", sb.res ) sb.pet = fish.new( fishData ) -- Activate game after init completes sb.gameActive = true Runtime:addEventListener( "enterFrame", gameLoop ) print( "Init game completed!" ) end -------------------- -- STORYBOARD FUNC -------------------- function sceneGame:createScene( event ) print( "game.lua: Game Scene Created") -- Game space (Store in sb to allow access from classes) sb.gameSpace = self.view -- Initialize game initGame() -- Insert all display groups to game space sb.gameSpace:insert( sb.backGroup ) sb.gameSpace:insert( sb.midGroup ) sb.gameSpace:insert( sb.frontGroup ) print( "Scene fully created!" ) end function sceneGame:destroyScene( event ) Runtime:removeEventListener( "enterFrame", gameLoop ) -- NYI end sceneGame:addEventListener( "createScene" ) sceneGame:addEventListener( "destroyScene" ) return sceneGame
fishclass.lua
-------------------- -- REQUIRE -------------------- -- STORYBOARD local sb = require "storyboard" -------------------- -- ENUM -------------------- local state = { idle = "idle", move = "move", eat = "eat", play = "play", sleep= "sleep" } -------------------- -- FISH CLASS -------------------- local fish = {} local fish\_mt = { \_\_index = fish } -- CONSTRUCTOR function fish.new( fishData ) print( "Creating fish..." ) -- Create the instance of the fish (sprite) local fishSheet = graphics.newImageSheet( fishData.sheetPath, fishData.sheetSetting ) local instance = display.newSprite( fishSheet, fishData.spriteSequence ) -- TEMPORARY instance:setSequence( state.idle ) instance:play() instance.x = display.contentWidth \* 0.5 instance.y = display.contentHeight \* 0.5 -- Add instance to middle group sb.midGroup:insert( instance ) print( "Fish created!" ) return setmetatable( instance, fish\_mt ) end -- MEMBER FUNCTIONS function fish:update() -- NYI end function fish:changeState( newState ) if ( self.state ~= newState ) then self.state = newState end end -- RETURN return fish