Changing text of text object makes objects disappear

Hi all,

I’ve been testing out some code that makes a simple keypad that is supposed to change a text field to a different number depending on which key is pressed. For some reason, after about 3 or 4 keypad clicks, the screen just goes blank. Any ideas why? My test code is below:

local testGroup = display.newGroup() function test() -- Display the equation box local eqBg = display.newRect(0, 0, 200, 50) eqBg:setFillColor(140, 140, 140) eqText = display.newText( "Hello", 0, 0, native.systemFont, 36 ) eqText.x = 80 eqText.y = 34 eqText:setTextColor( 255, 255, 255 ) local padKeys = {} for i=1,9 do -- create keypad buttons padKeys["key" .. i] = display.newRect(0, 0, 36, 36) padKeys["key" .. i]:setFillColor(10, 40, 85) padKeys["key" .. i]:setReferencePoint(display.TopLeftReferencePoint) padKeys["key" .. i].myNum = i padKeys["key" .. i]:addEventListener( "touch", addKeyNumeral ) end padKeys["key1"].x, padKeys["key1"].y = 10, 52 padKeys["key2"].x, padKeys["key2"].y = 70, 52 padKeys["key3"].x, padKeys["key3"].y = 130, 52 padKeys["key4"].x, padKeys["key4"].y = 10, 110 padKeys["key5"].x, padKeys["key5"].y = 70, 110 padKeys["key6"].x, padKeys["key6"].y = 130, 110 padKeys["key7"].x, padKeys["key7"].y = 10, 170 padKeys["key8"].x, padKeys["key8"].y = 70, 170 padKeys["key9"].x, padKeys["key9"].y = 130, 170 local eqGroup = display.newGroup() eqGroup:insert( eqText ) eqGroup["eqText"] = eqText testGroup["eqGroup"] = eqGroup end function addKeyNumeral(event) if ( event.phase == "ended" ) then print ("Adding a numeral...") testGroup.eqGroup.eqText.text = event.target.myNum end return true end test()

Are you getting any errors in your console?

I tested it, seemed to work fine. 

No, I’m not getting an console errors, which seems weird. What’s happening is that after a seemingly random number of clicks on the different squares that make the keypad (e.g. 2, 3 sometimes up to 9), the screen just goes blank (all black). I ran a test that shows the program is still alive - that is, it can execute further code, but nothing is visible. My Corona version is 2013.1137.

Hi guys,

Thanks for your comments so far. As a further test, I simplified the code as below but am still finding the same problem. Sometimes it takes 10 or so clicks back and forth on the keypad boxes but the screen is still going black after a few clicks. I switched the simulator from ipad to iphone and saw the same thing. Any ideas on why the objects might be disappearing? 

Here’s the simplified code stored in main.lua. I opened it in a fresh directory with no other files or config set:

function test() eqText = display.newText( "Hello", 0, 0, native.systemFont, 36 ) eqText.x = 80 eqText.y = 34 eqText:setTextColor( 255, 255, 255 ) padkey1 = display.newRect(0, 0, 36, 36) padkey1:setFillColor(10, 40, 85) padkey1:setReferencePoint(display.TopLeftReferencePoint) padkey1.myNum = 1 padkey1:addEventListener( "touch", addKeyNumeral ) padkey1.x, padkey1.y = 10, 152 padkey2 = display.newRect(0, 0, 36, 36) padkey2:setFillColor(10, 40, 85) padkey2:setReferencePoint(display.TopLeftReferencePoint) padkey2.myNum = 2 padkey2:addEventListener( "touch", addKeyNumeral ) padkey2.x, padkey2.y = 70, 152 end function addKeyNumeral(event) if ( event.phase == "ended" ) then print ("Adding a numeral...") eqText.text = event.target.myNum end return true end test()

Also, if I add the line:

print ("visibility of keypad1: " … tostring(event.target.isVisible) )

after setting the text in addKeyNumberal, it prints true, even after the object has disappeared from the screen.

Hi @jeff15,

To assist, we probably need to see some error log or Terminal error messages if you can supply them.

Thanks,

Brent

Yeah, if I could find one, I’d send it along! :slight_smile: I think it might be hardware specific though, because I just tried it on a Dell laptop and I’m not seeing objects disappear. Have you ever seen anything like this related to graphics cards or other hardware? And is there another way to check for errors other than the Terminal window? As I mentioned above, the code continues to work since I can execute other functions. It’s just that the screen goes blank.

Hi Jeff,

It could be a graphics card/hardware or driver issue. Did you get a chance to test this on any other machines?

Hi Brent, yes, I tried it on another machine and it seems okay. So do you think the graphics card driver is the first thing to try? Have you heard of anything like this before?

I did see a comment from last year (http://www.coronalabs.com/blog/2012/03/27/storyboard-scene-events-explained/) where someone said the screen when blank after reloading a scene (referring to build 2012-776) but it was a different situation. Still, wondering if it might be related. 

Hi Brent, I’m happy to report that updating my graphics driver solved the problem!

Thanks for everyone’s help and suggestions!

Cheers,

Jef

Are you getting any errors in your console?

I tested it, seemed to work fine. 

No, I’m not getting an console errors, which seems weird. What’s happening is that after a seemingly random number of clicks on the different squares that make the keypad (e.g. 2, 3 sometimes up to 9), the screen just goes blank (all black). I ran a test that shows the program is still alive - that is, it can execute further code, but nothing is visible. My Corona version is 2013.1137.

Hi guys,

Thanks for your comments so far. As a further test, I simplified the code as below but am still finding the same problem. Sometimes it takes 10 or so clicks back and forth on the keypad boxes but the screen is still going black after a few clicks. I switched the simulator from ipad to iphone and saw the same thing. Any ideas on why the objects might be disappearing? 

Here’s the simplified code stored in main.lua. I opened it in a fresh directory with no other files or config set:

function test() eqText = display.newText( "Hello", 0, 0, native.systemFont, 36 ) eqText.x = 80 eqText.y = 34 eqText:setTextColor( 255, 255, 255 ) padkey1 = display.newRect(0, 0, 36, 36) padkey1:setFillColor(10, 40, 85) padkey1:setReferencePoint(display.TopLeftReferencePoint) padkey1.myNum = 1 padkey1:addEventListener( "touch", addKeyNumeral ) padkey1.x, padkey1.y = 10, 152 padkey2 = display.newRect(0, 0, 36, 36) padkey2:setFillColor(10, 40, 85) padkey2:setReferencePoint(display.TopLeftReferencePoint) padkey2.myNum = 2 padkey2:addEventListener( "touch", addKeyNumeral ) padkey2.x, padkey2.y = 70, 152 end function addKeyNumeral(event) if ( event.phase == "ended" ) then print ("Adding a numeral...") eqText.text = event.target.myNum end return true end test()

Also, if I add the line:

print ("visibility of keypad1: " … tostring(event.target.isVisible) )

after setting the text in addKeyNumberal, it prints true, even after the object has disappeared from the screen.

Hi @jeff15,

To assist, we probably need to see some error log or Terminal error messages if you can supply them.

Thanks,

Brent

Yeah, if I could find one, I’d send it along! :slight_smile: I think it might be hardware specific though, because I just tried it on a Dell laptop and I’m not seeing objects disappear. Have you ever seen anything like this related to graphics cards or other hardware? And is there another way to check for errors other than the Terminal window? As I mentioned above, the code continues to work since I can execute other functions. It’s just that the screen goes blank.

Hi Jeff,

It could be a graphics card/hardware or driver issue. Did you get a chance to test this on any other machines?

Hi Brent, yes, I tried it on another machine and it seems okay. So do you think the graphics card driver is the first thing to try? Have you heard of anything like this before?

I did see a comment from last year (http://www.coronalabs.com/blog/2012/03/27/storyboard-scene-events-explained/) where someone said the screen when blank after reloading a scene (referring to build 2012-776) but it was a different situation. Still, wondering if it might be related.