Composer change over causes crash lapp.

Hi;

I am in the process of updating one of my projects to use the Composer API. However, I followed the tutorial, made the changes and now the App simply loads the main.lua file but hang on a black screen. I can’t figure out what is wrong with it. Please see below for more info:

Terminal out put = 2014-04-17 16:40:51.452 Corona Simulator[1022:507] Initial Main.lua loaded

code:

display.setStatusBar( display.HiddenStatusBar )

require(“globals”)

require(“globalFunctions”)

local composer = require( “composer” )

local scene = composer.newScene()

local myAnimation

local sheetData1

local sheet1

local sequenceData

print (“Initial Main.lua loaded”)

---- Functions

local function continueTrans(event)

    

    

    local options = {

    effect = “fade”,

    time = 500,

    params = {

        someKey = “someValue”,

        someOtherKey = 10

        }

    }

    composer.gotoScene( “mainMenu”, options )

end

– “scene:create()”

function scene:create( event )

   local sceneGroup = self.view

   – Initialize the scene here.

   – Example: add display objects to “sceneGroup”, add touch listeners, etc.

   

       print (“scene:create before animation is loaded Main.lua loaded”)

       

       

      

        sheetData1 = { width=300, height=300, numFrames=3, sheetContentWidth=900, sheetContentHeight=300 }

        sheet1 = graphics.newImageSheet( “loadinganimation.png”, sheetData1 )

        

        sequenceData = {

                        { name=“seq1”, sheet=sheet1, start=1, count=3, time=3000, loopCount=1 },

                        --{ name=“seq2”, sheet=sheet2, start=1, count=6, time=220, loopCount=0 }

                        }

        myAnimation = display.newSprite( sheet1, sequenceData )

        myAnimation.x = centerX ; myAnimation.y = centerY

        sceneGroup:insert(myAnimation)

      

        

        print (“scene:create Main.lua loaded”)

end

– “scene:show()”

function scene:show( event )

   local sceneGroup = self.view

   local phase = event.phase

   if ( phase == “will” ) then

      – Called when the scene is still off screen (but is about to come on screen).

      

      print (“scene:show-will Main.lua loaded”)

      composer.removeHidden()

      

   elseif ( phase == “did” ) then

      – Called when the scene is now on screen.

      – Insert code here to make the scene come alive.

      – Example: start timers, begin animation, play audio, etc.

      

        myAnimation:play()

       

        

        timer.performWithDelay(3400, continueTrans, 1) 

        

        print (“scene:show-did Main.lua loaded”)

   end

end

– “scene:hide()”

function scene:hide( event )

   local sceneGroup = self.view

   local phase = event.phase

   if ( phase == “will” ) then

      – Called when the scene is on screen (but is about to go off screen).

      – Insert code here to “pause” the scene.

      – Example: stop timers, stop animation, stop audio, etc.

   elseif ( phase == “did” ) then

      – Called immediately after scene goes off screen.

     

   end

end

– “scene:destroy()”

function scene:destroy( event )

   local sceneGroup = self.view

   – Called prior to the removal of scene’s view (“sceneGroup”).

   – Insert code here to clean up the scene.

   – Example: remove display objects, save state, etc.

end

Runtime:addEventListener( “memoryWarning”, handleLowMemory )

Runtime:addEventListener( “system”, onSystemEvent )


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene

------------------------------------ end code

I’m using daily build 2264.

I’m stumped. Any help would be greatly appreciated.

Cheers!

If that is the only output in your terminal, and this is all your code, maybe the Composer API is erroring out after the centerX/centerY variables are called, because I don’t see them explicitly declared in the code above. I haven’t used Composer much so I am not an expert, but that’s the first thing I would try to resolve.

Hi Panc;

Thanks for the reply however centerX and centerY are defined in the globals.lua file as such:

_G.w = display.contentWidth

_G.h = display.contentHeight

_G.centerX = w/2

_G.centerY = h/2

Cheers.

Do I have to have a .ccscene file or is that just for the new GUI?

Also, I forgot to mention that handleLowMemory onSystemEvent  are also in the globals file.

Still stumped.

Wasn’t aware that you could make main.lua into a scene. Normally you should always just require in composer and then gotoScene() to your first scene. Calling removeHidden here seems suspicious, too. 

Just for cleanliness (to avoid possible bugs) you don’t *have* to include the four scene commands in your files. You only need to include the ones you use. So in your code you could drop hide() and destroy() (along with their :addEventListener calls)

I would break out the scene into a seperate lua file. Then, if there’s still an issue, start commenting out code and see what happens.

main.lua should not be a scene.  Just require composer and call composer.gotoScene() on your first scene.

Rob

OK thanks for your reply. I put the remove Hidden in there because I wasn’t quite sure were to put it. LOL  :lol:

Thanks For your reply.

So never use main.lua to do anything except goto my first scene yeah!?  OK I did not know that. Still learning.  :smiley:  

I will make that adjustment and see what happens.

Cheers! 

This seems to have done the trick. Thanks guys.

It’s okay to put composer.removeHidden in main.lua.   When using Composer (or previously Storyboard), main.lua is a place to initialize every thing.  Since it’s not a scene, you won’t be going back to it.  You can load sounds that you want all the time, initialize ads or in-app purchases, put in your facebook.init() etc.  As such main.lua will frequently contain all of the listener functions for these items.  You can set up any hardware  listeners, like key listeners, tilt events etc.

Since composer.removeHidden is a setup feature it’s fine to put in main.lua.  Then at the end of your main.lua you do a gotoScene() to your first scene and from then on your app bounces between the various scenes.

One slight exception this (but not really when you think about it) is building a tabBar  based app.  In Corona any display objects that are not inserted into a scene, stay on top of the scenes.  You can create your widget.newTabBar() in main.lua and  have each tab load a scene.  You don’t really go back to main.lua, but the tabBar  has the statements to change scenes (Like in the Business App Sample (https://github.com/coronalabs/business-app-sample).

Rob

OK thanks for all of the info, I appreciate your time, I know you guys are busy.

That is good to know. I will definitely take another look at the business app sample.

Are all the sample apps up to date (for instance: Graphics 2.0, composer, etc.) ?

Cheers!

If that is the only output in your terminal, and this is all your code, maybe the Composer API is erroring out after the centerX/centerY variables are called, because I don’t see them explicitly declared in the code above. I haven’t used Composer much so I am not an expert, but that’s the first thing I would try to resolve.

Hi Panc;

Thanks for the reply however centerX and centerY are defined in the globals.lua file as such:

_G.w = display.contentWidth

_G.h = display.contentHeight

_G.centerX = w/2

_G.centerY = h/2

Cheers.

Do I have to have a .ccscene file or is that just for the new GUI?

Also, I forgot to mention that handleLowMemory onSystemEvent  are also in the globals file.

Still stumped.

Wasn’t aware that you could make main.lua into a scene. Normally you should always just require in composer and then gotoScene() to your first scene. Calling removeHidden here seems suspicious, too. 

Just for cleanliness (to avoid possible bugs) you don’t *have* to include the four scene commands in your files. You only need to include the ones you use. So in your code you could drop hide() and destroy() (along with their :addEventListener calls)

I would break out the scene into a seperate lua file. Then, if there’s still an issue, start commenting out code and see what happens.

main.lua should not be a scene.  Just require composer and call composer.gotoScene() on your first scene.

Rob

OK thanks for your reply. I put the remove Hidden in there because I wasn’t quite sure were to put it. LOL  :lol:

Thanks For your reply.

So never use main.lua to do anything except goto my first scene yeah!?  OK I did not know that. Still learning.  :smiley:  

I will make that adjustment and see what happens.

Cheers!