Crashes on entering game from menu with HTC Desire HD, works perfect in Android Simulator

Hi, this is really confusing for me. The app works perfectly in the simulator but just gives a blank screen and crashes with NO error messages on my HTC Desire HD when pressing the start game button.

Here is the main.lua file that just loads up the menu.lua file.

This works!

\_H = display.contentHeight;  
\_W = display.contentWidth;  
  
local director = require("director");  
  
local mainGroup = display.newGroup();  
  
local function main()  
  
 mainGroup:insert(director.directorView);  
  
 director:changeScene("menu");  
  
 return true;  
end  
  
main();  

This is the menu.lua file, which crashes the app when pressing on the text to go to the game.lua file.

[code]module(…, package.seeall)

function new()
local localGroup = display.newGroup();

– Use the system name for the font (click on font)

– *2 = Retina Display Support
local hello = display.newText(“Tap me, and magic happens!”, 0, 0, “BorisBlackBloxx”, 24*2)
– Xscale = retina support
hello.xScale = 0.5; hello.yScale = 0.5;
hello.x = _W * 0.5; hello.y = _H * 0.5;
hello.scene = “game”;

function changeScene(e)
if(e.phase == “ended”) then
– e.target is in this case = “game”)
director:changeScene(e.target.scene);
end
end

localGroup:insert(hello);

– Adds a touch event to the buttons and activates the function
hello:addEventListener(“touch”, changeScene);

return localGroup;
end[/code]

And this is the game.lua file that never loads:

module(..., package.seeall)  
  
function new()  
 local localGroup = display.newGroup();  
  
 local hero = display.newImageRect("images/hero.png", 100, 82);  
 hero:setReferencePoint(display.CenterReferencePoint);  
 hero.x = \_W/2; hero.y = \_H/2;  
  
 local touchleft = display.newImageRect("images/leftbutton.png", 51, 48);  
 touchleft:setReferencePoint(display.CenterReferencePoint);  
 touchleft.x = 40; touchleft.y = 210;  
  
 local touchright = display.newImageRect("images/leftbutton.png", 51, 48);  
 touchright:setReferencePoint(display.CenterReferencePoint);  
 touchright.x = 140; touchright.y = 210;  
 touchright.rotation = -180;  
  
 local touchdown = display.newImageRect("images/leftbutton.png", 51, 48);  
 touchdown:setReferencePoint(display.CenterReferencePoint);  
 touchdown.x = 90; touchdown.y = 260;  
 touchdown.rotation = -90;  
  
 local touchup = display.newImageRect("images/leftbutton.png", 51, 48);  
 touchup:setReferencePoint(display.CenterReferencePoint);  
 touchup.x = 90; touchup.y = 160;  
 touchup.rotation = 90;  
  
 function touchleft1(e)  
 if(e.phase == "ended") then  
 transition.to(hero, {time = 1000, x= hero.x - hero.width});  
 end  
 end  
  
 function touchright1(e)  
 if(e.phase == "ended") then  
 transition.to(hero, {time = 1000, x= hero.x + hero.width});  
 end  
 end  
  
 function touchdown1(e)  
 if(e.phase == "ended") then  
 transition.to(hero, {time = 1000, y= hero.y + hero.width});  
 end  
 end  
  
 function touchup1(e)  
 if(e.phase == "ended") then  
 transition.to(hero, {time = 1000, y= hero.y - hero.width});  
 end  
 end  
  
 localGroup:insert(hero);  
 localGroup:insert(touchleft);  
 localGroup:insert(touchright);  
 localGroup:insert(touchdown);  
 localGroup:insert(touchup);  
  
 touchleft:addEventListener("touch", touchleft1);  
 touchright:addEventListener("touch", touchright1);  
 touchdown:addEventListener("touch", touchdown1);  
 touchup:addEventListener("touch", touchup1);  
  
 return localGroup;  
end  

Does anyone have any idea what may be causing this?

Thanks in advance,
Fredrik [import]uid: 43150 topic_id: 7779 reply_id: 307779[/import]

I have now simplified the code and If I use a local text object in the scene screen1.lua it works and looks like this. BUT it doesn’t work when I use a local image instead like the last code in this post.

main.lua

  
-- import the director class  
local director = require("director")  
  
-- Create a main group  
local mainGroup = display.newGroup()  
  
-- Main function  
local function main()  
  
 -- Add the group from the director class   
 mainGroup:insert(director.directorView)  
  
 -- Change scene without effects  
 director:changeScene("intro")  
  
 return true  
end  
  
-- Begin  
main()  

intro.lua

module(..., package.seeall)  
  
local localGroup  
  
-- Main function - MUST return a display.newGroup  
function new()  
  
 localGroup = display.newGroup()  
  
 \_H = display.contentHeight  
 \_W = display.contentWidth  
  
 local introtext = display.newText("Tap me, and magic happens!", 0, 0, "BorisBlackBloxx", 24\*2)  
 introtext.xScale = 0.5  
 introtext.yScale = 0.5  
 introtext.x = \_W \* 0.5  
 introtext.y = \_H \* 0.5  
 localGroup:insert(introtext)  
  
 -- Touch to go to forward  
 local function touched ( event )  
 if event.phase == "ended" then  
 director:changeScene("screen1","fade")  
 end  
 end  
 introtext:addEventListener("touch", touched)  
  
 -- MUST return a display.newGroup()  
 return localGroup  
end  

screen1.lua

module(..., package.seeall)  
  
local localGroup  
  
-- Main function - MUST return a display.newGroup  
function new()  
  
 localGroup = display.newGroup()  
  
 \_H = display.contentHeight  
 \_W = display.contentWidth  
  
 local introtext = display.newText("It worked!", 0, 0, "BorisBlackBloxx", 24\*2)  
 introtext.xScale = 0.5  
 introtext.yScale = 0.5  
 introtext.x = \_W \* 0.5  
 introtext.y = \_H \* 0.5  
 localGroup:insert(introtext)  
  
 -- MUST return a display.newGroup()  
 return localGroup  
end  

It won’t go to the screen1.lua and is stuck on intro.lua when the screen1 code looks like this:

module(..., package.seeall)  
  
local localGroup  
  
-- Main function - MUST return a display.newGroup  
function new()  
 localGroup = display.newGroup()  
  
 -- The hero  
 local hero = display.newImage("images/hero.png", 100, 82)  
 localGroup:insert(hero)  
  
 -- MUST return a display.newGroup()  
 return localGroup  
end  

Any ideas? T_T [import]uid: 43150 topic_id: 7779 reply_id: 27631[/import]

I do not have an android device, but I think it may not work because you have your images in a sub directory “images/hero.png”.

I think I read that causes a problem on actual devices using android?

I would try putting the images in the main directory with your code and changing the code to just “hero.png” etc [import]uid: 8366 topic_id: 7779 reply_id: 27635[/import]

THANK YOU! Now it works just fine.
It’s kind of wierd that I could use subfolders when not using the Director class and just one screen, but I’ll just skip the subfolders for the android version now. [import]uid: 43150 topic_id: 7779 reply_id: 27638[/import]