Landscape orientation on iPad results in flickering

My app flickers when I hold the iPad in horizontal position. It seems that an “enterScene” event is produced randomly. It makes it impossible to fill out a form field in my app because the screen redraws after inputting a couple of characters leaving the form field empty again. The screen also redraws spontaneously without any interaction.

When held vertically (portrait) there is no flickering and all works well.

My build settings are:

[LUA]

orientation = 

    {

        default = “portrait”,

        supported = 

        {

            “portrait”, “portraitUpsideDown”, “landscapeLeft”, “landscapeRight”

        },

    },

[/LUA]

I am building with Corona version 2013.1247,

Anyone seen this situation and figured out a solution?

Thanks

Hi @leomb,

Did this happen on an earlier build, or just this one? Can you test it on an earlier daily build, and public build #1202 as well?

Thanks,

Brent Sorrentino

Hi Brent,

This also happened on earlier builds. I followed your suggestion and built using #1202 to compare. Same issue. What I did notice though is that holding the iPad horizontally but in an upright position (90°) there is no flickering/sceneEnter event. When I lower the iPad to a 29° angle the flickering starts again. (I measured with the Gyroscope app). No other apps on my iPad have this issue. 

Ultimately I can limit my app to portrait mode but my client might not be too happy about that…

I have a total of 8 scenes, some with masks, and the flickering happens on all of them, including the splash screen.

I am eager to know what your thoughts are!

Thanks,

Leonardo

Can you reduce this to a simple test case?  I just ran one of my apps that uses storyboard and I moved it back and forth in landscape mode and didn’t see any flickering.  Albeit my app is locked into landscape mode.

Have you put in print statements into your enterScene()'s to verify they are triggering randomly?  Do you have gyroscope event handlers setup?

Are there any timers doing mischievous things?  

Hi Rob, I stripped my app down to the first two lua files and took every other file out of my project folder. The splash screen still flickers (my iPad lies on my desk slightly tilted up by the roll-up smart cover)

Below is the code of the main.lua and the first 29 lines of my splash.lua file. Could the culprit be my onOrientationChange function? But why does it flicker in landscape mode yet not in portrait mode?

main.lua:

[LUA]

local storyboard = require(“storyboard”)

require “sqlite3”

– hide the status bar

display.setStatusBar(display.TranslucentStatusBar)

local background = display.newImage(“mountainsPL.png”)

background.y = display.actualContentHeight/2 + display.topStatusBarContentHeight/2

local display_stage = display.getCurrentStage()

display_stage:insert( background )

display_stage:insert( storyboard.stage )

– set up database and the two tables (flight and legs)

local dbPath = system.pathForFile( “fo.sqlite”, system.DocumentsDirectory )

db = sqlite3.open( dbPath )

– setup flight table if it doesn’t exist

local flightTableSetup = “CREATE TABLE IF NOT EXISTS flight (id INTEGER PRIMARY KEY, flightNumber VARCHAR(30), flightDate VARCHARS(10), aircraft CHAR(10), signIn CHAR(4), signOut CHAR(4), rules CHAR(3), UNIQUE (flightNumber));”

db:exec( flightTableSetup )

local legTableSetup = “CREATE TABLE IF NOT EXISTS leg ( flightId INTEGER, legNumber TINYINT, airportDept CHAR(4), airportArr CHAR(4), timeOut CHAR(4), timeOff CHAR(4), timeOn CHAR(4), timeIn CHAR(4), oil TINYINT, fuelRelease SMALLINT, fuelOff SMALLINT, fuelLanding SMALLINT, pilot1 VARCHAR(75), pilot2 VARCHAR(75), pilot3 VARCHAR(75), pax TEXT, UNIQUE(legNumber) );”

db:exec( legTableSetup )

local passengerTableSetup = “CREATE TABLE IF NOT EXISTS passengers ( aircraft CHAR(10), fname VARCHAR(70), lname VARCHAR(70), nationality(12), passpor VARCHAR(20), passport_exp VARCAHR(15), dob DATE, address VARCHAR(100), city VARCHAR(25), state VARCHAR(25), country VARCHAR(25), phone VARCHAR(25), visa_exp DATE);”

db:exec( passengerTableSetup )

    

local function onSystemEvent( event )

    if( event.type == “applicationExit” ) then              

        db:close()

    end

end

    

storyboard.gotoScene(“splash”)

[/LUA]

splash.lua:

[LUA]

local storyboard = require “storyboard”

local scene = storyboard.newScene()

– forward declarations

local group

function scene:createScene( event )

    group = self.view

    local function onOrientationChange( event )

        local currentOrientation = event.type

        print( "Current orientation: " … currentOrientation )

        storyboard.reloadScene()

    end

    Runtime:addEventListener( “orientation”, onOrientationChange )

    

    local splashImage, startButtonTop, infoBoxY

    if system.orientation == “portrait” or system.orientation == “portraitUpsideDown” then

        splashImage = “Default-Portrait.png”

        startButtonTop = 915

        infoBoxY = 544

    else

        splashImage = “Default-Landscape.png”

        startButtonTop = 653

        infoBoxY = 495

    end

    

    local splash = display.newImage(group, splashImage)

[/LUA]

I appreciate your help in this!

Leonardo

To answer your other questions:

I don’t have any issues on the Simulator, only on the iPad device, so print statements cannot be used for debugging this problem.

I used a Gysroscope app on my iPod laid on top of my iPad to figure out the point where it flickers. I had not noticed that we have a gyroscope event; good to know!

I have a timer on one scene but it’s only triggered by user input (after tapping on a button). In my stripped down test this scene was not in the project.

Leonardo

First of all, print statements are highly usable on device.  See:  http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

I suspect that your onOrientation is the culprit.  If reloadScene() causes createScene() to run a second time, you’re not doing your onOrientation Twice. And the reloadScene() is potentially going to cause a flicker too.

I checked out the console on Xcode  (thanks for pointing this out!) and I see that the orientation event is fired multiple times spontaneously. The orientation type is either " landscapeLeft" or " faceUp" as reported on the console.

The device is on my desk, slightly tilted, one of the long sides held up by the roll-up smart cover. 

But here is something interesting: When I manually hold up the opposite side, no orientation events are fired and there is no flickering!

So now I’m confused. I need the orientation event because I have two background images (horizontal and vertical). The layout of buttons and form fields are also adjusted for orientation.

How do I deal with these two spontaneous orientation events? Why are they even firing when the device is lying still?  

Without seeing your orientation code, it’s hard to advise, but if you don’t care about the faceUp event, just throw it away.  As to why it fires with the ipad still, maybe it’s an initial setup or something.

I’ve only used it in one app and  was only look for portraitUpsideDown in it and I never noticed it firing off. 

Rob

The orientation code is still the same as listed above in the spash.lua file. (After watching your excellent Reloading Storyboard Scenes video tutorial several times I tried the orientation code out of the willEnterScene and enterScene functions but that didn’t help in my case).

I actually tried ignoring the faceUp orientation by adding to the code:

elseif system.orientation == "faceUp"

    – do nothing

else …

but this resulted in my background image disappearing altogether.

I wonder if it’s possible to handle the faceUp event by doing a full 180° rotation of the scene, forcing the user to rotate the device? :slight_smile: But I guess not…

Leonardo

I think the best thing to do here to narrow this down is:

  1. make a small example of what you are doing, but keep it contained to a main.lua file and do not use storyboard.

  2. add in your orientation stuff.

  3. see if the issue still occurs.

If the issue still occurs after step 3, then post up the full code to the test version and we will then know if you are doing something wrong or if there is a corona bug that you have found.

I think this would help everyone and save a lot of back and forth.

Thanks!

Ok Danny, I can confirm that the issue is there with the bare minimum of code.

All you need to do is:

  1. Lay the iPad flat on the desk, slightly tilted wide side up, using the smart cover

  2. Start the app and watch the Xcode console.

  3. A tap on the screen is enough to trigger a series of rotation events of type faceUp and landscapeLeft , and occasionally portrait.

config.lua:

[LUA]

application = 

{

    content =

    {

        width = 768,

        height = 1024,

        scale = “letterbox”,

        xalign = “center”,

        yalign = “center”,

        imageSuffix = 

        {

            ["@2"] = 2,

            ["@4"] = 4

        }

    }

}

[/LUA]

main.lua:

[LUA]


– main.lua


– Your code here

local function onOrientationChange( event )

    local currentOrientation = event.type

    print( "Current orientation: " … currentOrientation )

end

Runtime:addEventListener( “orientation”, onOrientationChange )

[/LUA]

Version 2.0.0

Build: 2013.1202

Please let me know if I need to do a bug report.

Thanks!

I just tried your code with the latest Graphics 2.0 build and I’m seeing the same issue.  Please file a bug report and post the bug report number back to this thread.

Thanks

Rob

A bug report has been filed for this issue:

(Case 27672) Spontaneous and random firing of orientationChange event on iPad

Hi @leomb,

Did this happen on an earlier build, or just this one? Can you test it on an earlier daily build, and public build #1202 as well?

Thanks,

Brent Sorrentino

Hi Brent,

This also happened on earlier builds. I followed your suggestion and built using #1202 to compare. Same issue. What I did notice though is that holding the iPad horizontally but in an upright position (90°) there is no flickering/sceneEnter event. When I lower the iPad to a 29° angle the flickering starts again. (I measured with the Gyroscope app). No other apps on my iPad have this issue. 

Ultimately I can limit my app to portrait mode but my client might not be too happy about that…

I have a total of 8 scenes, some with masks, and the flickering happens on all of them, including the splash screen.

I am eager to know what your thoughts are!

Thanks,

Leonardo

Can you reduce this to a simple test case?  I just ran one of my apps that uses storyboard and I moved it back and forth in landscape mode and didn’t see any flickering.  Albeit my app is locked into landscape mode.

Have you put in print statements into your enterScene()'s to verify they are triggering randomly?  Do you have gyroscope event handlers setup?

Are there any timers doing mischievous things?  

Hi Rob, I stripped my app down to the first two lua files and took every other file out of my project folder. The splash screen still flickers (my iPad lies on my desk slightly tilted up by the roll-up smart cover)

Below is the code of the main.lua and the first 29 lines of my splash.lua file. Could the culprit be my onOrientationChange function? But why does it flicker in landscape mode yet not in portrait mode?

main.lua:

[LUA]

local storyboard = require(“storyboard”)

require “sqlite3”

– hide the status bar

display.setStatusBar(display.TranslucentStatusBar)

local background = display.newImage(“mountainsPL.png”)

background.y = display.actualContentHeight/2 + display.topStatusBarContentHeight/2

local display_stage = display.getCurrentStage()

display_stage:insert( background )

display_stage:insert( storyboard.stage )

– set up database and the two tables (flight and legs)

local dbPath = system.pathForFile( “fo.sqlite”, system.DocumentsDirectory )

db = sqlite3.open( dbPath )

– setup flight table if it doesn’t exist

local flightTableSetup = “CREATE TABLE IF NOT EXISTS flight (id INTEGER PRIMARY KEY, flightNumber VARCHAR(30), flightDate VARCHARS(10), aircraft CHAR(10), signIn CHAR(4), signOut CHAR(4), rules CHAR(3), UNIQUE (flightNumber));”

db:exec( flightTableSetup )

local legTableSetup = “CREATE TABLE IF NOT EXISTS leg ( flightId INTEGER, legNumber TINYINT, airportDept CHAR(4), airportArr CHAR(4), timeOut CHAR(4), timeOff CHAR(4), timeOn CHAR(4), timeIn CHAR(4), oil TINYINT, fuelRelease SMALLINT, fuelOff SMALLINT, fuelLanding SMALLINT, pilot1 VARCHAR(75), pilot2 VARCHAR(75), pilot3 VARCHAR(75), pax TEXT, UNIQUE(legNumber) );”

db:exec( legTableSetup )

local passengerTableSetup = “CREATE TABLE IF NOT EXISTS passengers ( aircraft CHAR(10), fname VARCHAR(70), lname VARCHAR(70), nationality(12), passpor VARCHAR(20), passport_exp VARCAHR(15), dob DATE, address VARCHAR(100), city VARCHAR(25), state VARCHAR(25), country VARCHAR(25), phone VARCHAR(25), visa_exp DATE);”

db:exec( passengerTableSetup )

    

local function onSystemEvent( event )

    if( event.type == “applicationExit” ) then              

        db:close()

    end

end

    

storyboard.gotoScene(“splash”)

[/LUA]

splash.lua:

[LUA]

local storyboard = require “storyboard”

local scene = storyboard.newScene()

– forward declarations

local group

function scene:createScene( event )

    group = self.view

    local function onOrientationChange( event )

        local currentOrientation = event.type

        print( "Current orientation: " … currentOrientation )

        storyboard.reloadScene()

    end

    Runtime:addEventListener( “orientation”, onOrientationChange )

    

    local splashImage, startButtonTop, infoBoxY

    if system.orientation == “portrait” or system.orientation == “portraitUpsideDown” then

        splashImage = “Default-Portrait.png”

        startButtonTop = 915

        infoBoxY = 544

    else

        splashImage = “Default-Landscape.png”

        startButtonTop = 653

        infoBoxY = 495

    end

    

    local splash = display.newImage(group, splashImage)

[/LUA]

I appreciate your help in this!

Leonardo

To answer your other questions:

I don’t have any issues on the Simulator, only on the iPad device, so print statements cannot be used for debugging this problem.

I used a Gysroscope app on my iPod laid on top of my iPad to figure out the point where it flickers. I had not noticed that we have a gyroscope event; good to know!

I have a timer on one scene but it’s only triggered by user input (after tapping on a button). In my stripped down test this scene was not in the project.

Leonardo

First of all, print statements are highly usable on device.  See:  http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

I suspect that your onOrientation is the culprit.  If reloadScene() causes createScene() to run a second time, you’re not doing your onOrientation Twice. And the reloadScene() is potentially going to cause a flicker too.