App freezes on iPad, not in simulator

I’ve been using a template to put together a simple game app with the Corona SDK, and everything’s been going fine whenever I’ve been using Corona to simulate it on a piece of hardware.

However, upon building it and testing it on my iPad, the game gets stuck when you select a character (which should mean quitting the main menu & starting the game itself) - the button is clicked, but nothing happens, and nothing else can be pressed at that point.

If someone has the time, I’d greatly appreciate it if someone could have a look over the code and point out where I’ve gone wrong.

Hi teleros.  There are several reasons why things won’t work on a device when they do in the simulator.  However, it’s a guessing game unless you want to attach your device to  your computer and read the device’s console log.  Any errors will be presented there.  If you do not know how to do that, please read this tutorial:

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Rob

Here’s the output when I do so:

2014-08-09 19:45:35.810 Corona Simulator[308:507] 480

2014-08-09 19:45:35.812 Corona Simulator[308:507] WARNING: The ‘ads’ library is not available on this platform

In spite of that, the game works fine in the simulator, as I mentioned. Anyway, 480 I’m assuming is a reference to a particular line of code, but that’s not terribly helpful:

-gameScene.lua has over 480 lines (it’s the only file with that many in fact), but #480 is just a couple of spaces:

479  group.gameSpeed = gameSpeed;

480 
481  currentScore = restartScore+0;

First of all, this is output from the Corona simulator, not from your iPad.  You  have to plug your iPad into your computer with it’s USB charging/sync cable.  Then you have to use Xcode’s Organizer to look at the device’s console log.  This was all detailed in the tutorial.

Secondly, this line:

2014-08-09 19:45:35.810 Corona Simulator[308:507] 480

is probably the result of a line of code that reads:  print(display.contentWidth)    (or perhaps display.contentWidth, or some other print statement).  The “ads not available” entry is because ad providers do not work in the simulator.  Please go back and get the console log from Xcode’s Organizer while running the app on your iPad.

Rob

Here we go…

stack traceback: [C]: in function 'error' ?: in function 'gotoScene' .../menuScene.lua:153: in function 'touchEnded' .../library.lua:74: in function \<.../library:52\> ?: in function \<?:221\>

So, lines 52-78 (#74 is the last "        self:touchEnded();" BTW).

 function button:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus(self); self.isFocus = true; if self.touchBegan then self:touchBegan(); end return true; elseif event.phase == "moved" and self.isFocus then local bounds = self.contentBounds; if event.x \> bounds.xMax or event.x \< bounds.xMin or event.y \> bounds.yMax or event.y \< bounds.yMin then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end end return true; elseif event.phase == "ended" and self.isFocus then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end return true; end end

There is probably more to the error than that.  Can you get several lines before that error?

Here’s the whole thing:

local gameLib = {}; gameLib.getSaveValue = function(key) if not gameLib.saveTable then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "r"); if file then local json = require "json"; gameLib.saveTable = json.decode(file:read("\*a")); io.close(file); end end gameLib.saveTable = gameLib.saveTable or {}; return gameLib.saveTable[key]; end gameLib.setSaveValue = function(key, value, operateSave) if not gameLib.saveTable then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "r"); if file then local json = require "json"; gameLib.saveTable = json.decode(file:read("\*a")); io.close(file); end end gameLib.saveTable = gameLib.saveTable or {}; gameLib.saveTable[key] = value; if operateSave then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "w+"); local json = require "json"; file:write(json.encode(gameLib.saveTable)); io.close(file); end return gameLib.saveTable[key]; end gameLib.newSimpleButton = function(group, img, width, height) local button = display.newImageRect(group or display.getCurrentStage(), img, width, height); function button:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus(self); self.isFocus = true; if self.touchBegan then self:touchBegan(); end return true; elseif event.phase == "moved" and self.isFocus then local bounds = self.contentBounds; if event.x \> bounds.xMax or event.x \< bounds.xMin or event.y \> bounds.yMax or event.y \< bounds.yMin then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end end return true; elseif event.phase == "ended" and self.isFocus then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end return true; end end button:addEventListener("touch", button); return button; end gameLib.convertRGB = function(r, g, b) return {r/255, g/255, b/255}; end return gameLib;

Everything prior to line 12 is just commented out notes etc.

I guess I wasn’t clear.  I meant more lines of your console log.  There is more to the error than you showed, you need to go back several lines and get the entire message.

Rob

Hi teleros.  There are several reasons why things won’t work on a device when they do in the simulator.  However, it’s a guessing game unless you want to attach your device to  your computer and read the device’s console log.  Any errors will be presented there.  If you do not know how to do that, please read this tutorial:

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Rob

Here’s the output when I do so:

2014-08-09 19:45:35.810 Corona Simulator[308:507] 480

2014-08-09 19:45:35.812 Corona Simulator[308:507] WARNING: The ‘ads’ library is not available on this platform

In spite of that, the game works fine in the simulator, as I mentioned. Anyway, 480 I’m assuming is a reference to a particular line of code, but that’s not terribly helpful:

-gameScene.lua has over 480 lines (it’s the only file with that many in fact), but #480 is just a couple of spaces:

479  group.gameSpeed = gameSpeed;

480 
481  currentScore = restartScore+0;

First of all, this is output from the Corona simulator, not from your iPad.  You  have to plug your iPad into your computer with it’s USB charging/sync cable.  Then you have to use Xcode’s Organizer to look at the device’s console log.  This was all detailed in the tutorial.

Secondly, this line:

2014-08-09 19:45:35.810 Corona Simulator[308:507] 480

is probably the result of a line of code that reads:  print(display.contentWidth)    (or perhaps display.contentWidth, or some other print statement).  The “ads not available” entry is because ad providers do not work in the simulator.  Please go back and get the console log from Xcode’s Organizer while running the app on your iPad.

Rob

Here we go…

stack traceback: [C]: in function 'error' ?: in function 'gotoScene' .../menuScene.lua:153: in function 'touchEnded' .../library.lua:74: in function \<.../library:52\> ?: in function \<?:221\>

So, lines 52-78 (#74 is the last "        self:touchEnded();" BTW).

 function button:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus(self); self.isFocus = true; if self.touchBegan then self:touchBegan(); end return true; elseif event.phase == "moved" and self.isFocus then local bounds = self.contentBounds; if event.x \> bounds.xMax or event.x \< bounds.xMin or event.y \> bounds.yMax or event.y \< bounds.yMin then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end end return true; elseif event.phase == "ended" and self.isFocus then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end return true; end end

There is probably more to the error than that.  Can you get several lines before that error?

Here’s the whole thing:

local gameLib = {}; gameLib.getSaveValue = function(key) if not gameLib.saveTable then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "r"); if file then local json = require "json"; gameLib.saveTable = json.decode(file:read("\*a")); io.close(file); end end gameLib.saveTable = gameLib.saveTable or {}; return gameLib.saveTable[key]; end gameLib.setSaveValue = function(key, value, operateSave) if not gameLib.saveTable then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "r"); if file then local json = require "json"; gameLib.saveTable = json.decode(file:read("\*a")); io.close(file); end end gameLib.saveTable = gameLib.saveTable or {}; gameLib.saveTable[key] = value; if operateSave then local path = system.pathForFile("savedData.json", system.DocumentsDirectory); local file = io.open(path, "w+"); local json = require "json"; file:write(json.encode(gameLib.saveTable)); io.close(file); end return gameLib.saveTable[key]; end gameLib.newSimpleButton = function(group, img, width, height) local button = display.newImageRect(group or display.getCurrentStage(), img, width, height); function button:touch(event) if event.phase == "began" then display.getCurrentStage():setFocus(self); self.isFocus = true; if self.touchBegan then self:touchBegan(); end return true; elseif event.phase == "moved" and self.isFocus then local bounds = self.contentBounds; if event.x \> bounds.xMax or event.x \< bounds.xMin or event.y \> bounds.yMax or event.y \< bounds.yMin then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end end return true; elseif event.phase == "ended" and self.isFocus then self.isFocus = false; display.getCurrentStage():setFocus(nil); if self.touchEnded then self:touchEnded(); end return true; end end button:addEventListener("touch", button); return button; end gameLib.convertRGB = function(r, g, b) return {r/255, g/255, b/255}; end return gameLib;

Everything prior to line 12 is just commented out notes etc.

I guess I wasn’t clear.  I meant more lines of your console log.  There is more to the error than you showed, you need to go back several lines and get the entire message.

Rob