[Resolved] App working in simulator but not on device

I have been making my app for ages and has worked perfectly so far. I decided to add a level select into the app and works fin in the simulator, but if i install the app on my android it crashes as soon as I go into the level select.

Code for drawing screen:

  
-- BACKGROUND IMAGE  
local backgroundImage = display.newImageRect( "mainmenu.png", 480, 320 )  
backgroundImage.x = 240; backgroundImage.y = 160  
  
menuGroup:insert( backgroundImage )  
  
-- LOCKED BUTTONS  
local lock1 = display.newImageRect("lock.png", 57, 57)  
lock1.x = 110; lock1.y = 100  
menuGroup:insert( lock1 )  
  
local lock2 = display.newImageRect("lock.png", 57, 57)  
lock2.x = 170; lock2.y = 100  
  
menuGroup:insert( lock2 )  
  
local lock3 = display.newImageRect("lock.png", 57, 57)  
lock3.x = 230; lock3.y = 100  
  
menuGroup:insert( lock3 )  
  
local lock4 = display.newImageRect("lock.png", 57, 57)  
lock4.x = 290; lock4.y = 100  
  
menuGroup:insert( lock4 )  
  
local lock5 = display.newImageRect("lock.png", 57, 57)  
lock5.x = 350; lock5.y = 100  
  
menuGroup:insert( lock5 )  
  
-- DATA LOAD DATA FILE  
local userdatafile = "save1.data"  
local curlvl = loadValue( userdatafile )  
  
local i = tonumber(curlvl)  
local x  
local lvl  
local levelBtn = {}  
  
-- EVENT FOR BUTTON CLICKS  
local onlevelBtn = function(event)  
 director:changeScene( "loadlevel" .. event.target.myId)  
end  
  
-- LEVEL BUTTONS  
while (i \> 0) do  
 levelBtn[i] = ui.newButton{  
 defaultSrc = "levelbtn.png",  
 defaultX = 57,  
 defaultY = 57,  
 overSrc = "levelbtn-over.png",  
 overX = 57,  
 overY = 57,  
 --onEvent = onlockBtn,  
 id = "LevelButton" .. i,  
 text = i,  
 font = "",  
 textColor = { 0, 0, 0, 255 },  
 size = 16,  
 emboss = false  
 }  
 levelBtn[i].myId = i  
  
 x = 50 + i \* 60;  
  
 levelBtn[i].x = x; levelBtn[i].y = 100  
  
 menuGroup:insert( levelBtn[i] )  
  
 levelBtn[i]:addEventListener("tap", onlevelBtn)  
  
 i = i - 1  
end  

I have noticed that when i remove the locked buttons from my app the level select works 100% just without the extra buttons. but as soon as i put them back in it crashes on the device just not the simulator.

I am really confused as to why this is happening. Does anyone have any idea?

Thnx,
Ultrasnofire [import]uid: 31078 topic_id: 27326 reply_id: 327326[/import]

Have you checked the console in Xcode?

Also, is this the entire levelselect.lua file? [import]uid: 52491 topic_id: 27326 reply_id: 111043[/import]

That is not the whole level select code, this is. I made some adjustments but still doesnt work.

  
module(..., package.seeall)  
  
-- Main function - MUST return a display.newGroup()  
function new()  
  
 local menuGroup = display.newGroup()  
  
 local ui = ui --require("ui")  
 local gameNetwork = require "gameNetwork"  
 --local ads = require "ads"  
  
 -- AUDIO  
 local tapSound = audio.loadSound( "tapsound.wav" )  
  
  
 --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
  
 -- saveValue() --\> used for saving high score, etc.  
  
 --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 local saveValue = function( strFilename, strValue )  
 -- will save specified value to specified file  
 local theFile = strFilename  
 local theValue = strValue  
  
 local path = system.pathForFile( theFile, system.DocumentsDirectory )  
  
 -- io.open opens a file at path. returns nil if no file found  
 local file = io.open( path, "w+" )  
 if file then  
 -- write game score to the text file  
 file:write( theValue )  
 io.close( file )  
 end  
 end  
  
 --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
  
 -- loadValue() --\> load saved value from file (returns loaded value as string)  
  
 --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 local loadValue = function( strFilename )  
 -- will load specified file, or create new file if it doesn't exist  
  
 local theFile = strFilename  
  
 local path = system.pathForFile( theFile, system.DocumentsDirectory )  
  
 -- io.open opens a file at path. returns nil if no file found  
 local file = io.open( path, "r" )  
 if file then  
 -- read all contents of file into a string  
 local contents = file:read( "\*a" )  
 io.close( file )  
 return contents  
 else  
 -- create file b/c it doesn't exist yet  
 file = io.open( path, "w" )  
 file:write( "1" )  
 io.close( file )  
 return "1"  
 end  
 end  
  
 local drawScreen = function()  
  
 -- BACKGROUND IMAGE  
 local backgroundImage = display.newImageRect( "mainmenu.png", 480, 320 )  
 backgroundImage.x = 240; backgroundImage.y = 160  
  
 menuGroup:insert( backgroundImage )  
  
 --ads.init( "inneractive", "IA\_GameTest" )  
 --ads.show( "banner", { x=0, y=0, interval=60 } )  
 -- LOAD DATA FILE  
 local userdatafile = "save1.data"  
 local curlvl = loadValue( userdatafile )  
  
 local i = tonumber(curlvl)  
 local x  
 local lvls = 5  
 local levelBtn = {}  
  
 -- EVENT FOR BUTTON CLICKS  
 local onlevelBtn = function(event)  
 director:changeScene( "loadlevel" .. event.target.myId)  
 end  
  
 while (lvls \> 0) do  
 if (lvls \<= i) then  
 -- LEVEL BUTTONS  
 levelBtn[lvls] = ui.newButton{  
 defaultSrc = "levelbtn.png",  
 defaultX = 57,  
 defaultY = 57,  
 overSrc = "levelbtn-over.png",  
 overX = 57,  
 overY = 57,  
 --onEvent = onlockBtn,  
 id = "LevelButton" .. lvls,  
 text = lvls,  
 font = "",  
 textColor = { 0, 0, 0, 255 },  
 size = 16,  
 emboss = false  
 }  
 levelBtn[lvls].myId = lvls  
  
 x = 50 + lvls \* 60;  
  
 levelBtn[lvls].x = x; levelBtn[lvls].y = 100  
  
 menuGroup:insert( levelBtn[lvls] )  
  
 levelBtn[lvls]:addEventListener("tap", onlevelBtn)  
  
 else  
 -- LOCKED BUTTONS  
 levelBtn[lvls] = ui.newButton{  
 defaultSrc = "lockbtn.png",  
 defaultX = 57,  
 defaultY = 57,  
 overSrc = "lockbtn-over.png",  
 overX = 57,  
 overY = 57,  
 --onEvent = onlockBtn,  
 id = "LevelButton" .. lvls,  
 text = lvls,  
 font = "",  
 textColor = { 0, 0, 0, 255 },  
 size = 16,  
 emboss = false  
 }  
 x = 50 + lvls \* 60;  
  
 levelBtn[lvls].x = x; levelBtn[lvls].y = 100  
  
 menuGroup:insert( levelBtn[lvls] )  
  
 end  
 lvls = lvls - 1  
 end  
 end  
  
 drawScreen()  
  
  
 local cleanSounds = function()  
 audio.stop()  
  
 if tapSound then  
 audio.dispose( tapSound )  
 tapSound = nil  
 end  
 end  
  
 clean = function()  
 cleanSounds()  
 end  
  
 -- MUST return a display.newGroup()  
 return menuGroup  
end  
  

I am running corona sdk on windows. But there is no errors being outputted in the console. [import]uid: 31078 topic_id: 27326 reply_id: 111049[/import]

just to make sure, lock.png isn’t by any chance Lock.png (not the case difference)?
[import]uid: 19626 topic_id: 27326 reply_id: 111060[/import]

robmiracle brings up a good point, the simulator is not case sensitive when it comes to file names and the device is so lock.png is the same as Lock.png in the simulator but once you build to the device then lock.png is different from Lock.png. 99% of the time when i find an error that only happens on the device it is due to cases in a file name. [import]uid: 126161 topic_id: 27326 reply_id: 111065[/import]

Thank you so much i spent ages looking for a problem and it turns out that the .png was .PNG on the image for some reason. [import]uid: 31078 topic_id: 27326 reply_id: 111092[/import]

It’s always a weird mix between “yay, fixed it!” and “damn, how did I miss that?” when it’s a capitalization issue - but am very happy to see this got sorted :wink:

Marking as resolved :slight_smile: [import]uid: 52491 topic_id: 27326 reply_id: 111109[/import]