Corona bug? App crashes when setting native textfield text and pressing undo button

Hi,

I’m working in a team on a fairly large education app. Because it is for education we need much better control and special features on how the user is able to edit and input text. That’s why we are building around the native text field to create a richer feature-set for user input, we need better control. So, enough of the prefacing.

When I run the very small example below, type in some characters and then press the undo button on the keyboard the app crashes. I’m on Corona SDK Version 2014.2189 (2014.3.6).

Edit: device tested on is iPad 4.

I have no idea what is causing this or more importantly how to solve it. Please help.

local nativeTextField = native.newTextField(500, 100, 100, 40) nativeTextField.userInput = function (self, event) if event.phase == "editing" then nativeTextField.text = 'foo' end end nativeTextField:addEventListener('userInput', nativeTextField)

Best Regards,

/Fredrik

Hi @Fredrik,

The way you’ve declared the function could be suspect here. Please refer to the documentation for this API, modify your code along these lines, and if you still get a crash, please submit it as a bug report case.

http://docs.coronalabs.com/api/library/native/newTextField.html

Thanks,

Brent

Hi Brent,

Thank you for your reply. I tried it again to be extra really super sure and it still crashes. I have submitted a bug like you suggested.

Best Regards,

/Fredrik

Hi @Fredrik,

The way you’ve declared the function could be suspect here. Please refer to the documentation for this API, modify your code along these lines, and if you still get a crash, please submit it as a bug report case.

http://docs.coronalabs.com/api/library/native/newTextField.html

Thanks,

Brent

Hi Brent,

Thank you for your reply. I tried it again to be extra really super sure and it still crashes. I have submitted a bug like you suggested.

Best Regards,

/Fredrik

Hi,

This has been fixed and will be in build 2340.

Corona Labs - Support
support@coronalabs.com

I got this in the mail yesterday! Hurrah!

Hi,

This has been fixed and will be in build 2340.

Corona Labs - Support
support@coronalabs.com

I got this in the mail yesterday! Hurrah!

I have the exact same problem with build 2381

It works fine on my iPhone4 and iPad2 with IOS 7.1.2. My client is using iPhone5 and 5S with IOS 7.1.2 and are reporting a crash when they touch the input field.

Hi @nun_dabold1,

Can you please post your code for the text field, and the listener function?

Thanks,

Brent

Sure, here’s the code. It’s wrapped in an IF statement so the fields are only displayed if you complete the level, the “editing” phase is supposed to limit the input to 6 characters but that doesn’t seem to work either so perhaps I’ve done something wrong here.

[lua]

local function textListener( event )

if ( event.phase == “began” ) then

– user begins editing text field

print( event.text )

elseif ( event.phase == “ended” or event.phase == “submitted” ) then

– text field loses focus

– do something with defaultField’s text

elseif ( event.phase == “editing” ) then

if string.len(event.text) >6 then

             event.text=string.sub (event.text, 1,6)

return true

            end

end

end

– Only show input fields if level was completed

if (score_sat==score_total) then

– Create text field

input1 = native.newTextField( display.contentCenterX, display.contentCenterY, 350, 45 )

input2 = native.newTextField( display.contentCenterX, display.contentCenterY+110, 350, 45 )

– Add default values

if (username~="") then

 input1.text=username

end

if (useremail~="") then

 input2.text=useremail

end

input1:addEventListener( “userInput”, textListener )

– Setup field size/font

local inputFontSize = 18/display.contentScaleY

local tHeight = 80

input1.font = native.newFont( native.systemFontBold, inputFontSize )

input1.size = inputFontSize

input1.height=tHeight

input2.font = native.newFont( native.systemFontBold, inputFontSize )

input2.size = inputFontSize

input2.height=tHeight

end – end check if level won

[/lua]

Hi @nun_dabold1,

Thanks for the code. Are you able to replicate a crash, or only your client? Would they be able to provide you with a crash report from the console if you asked for it and they are able (and know how) to locate it?

Thanks,

Brent

Hi Brent,

 Sadly I can’t replicate it. It works in the simulator, it works in the x-code simulator although when I switch to a 64 bit device, the app just does not show up on the simulator. It also works on my Android devices as well as iPad2, iPhone4.

 Client is not very technical so I don’t think they would be able to do that, I was posting here in the hope that someone had a similar experience and had found a solution.

 As the “editing” phase isn’t working correctly, I guess I’ll try removing the listener and see if they still have issues.

I have the exact same problem with build 2381

It works fine on my iPhone4 and iPad2 with IOS 7.1.2. My client is using iPhone5 and 5S with IOS 7.1.2 and are reporting a crash when they touch the input field.

Hi @nun_dabold1,

Can you please post your code for the text field, and the listener function?

Thanks,

Brent

Sure, here’s the code. It’s wrapped in an IF statement so the fields are only displayed if you complete the level, the “editing” phase is supposed to limit the input to 6 characters but that doesn’t seem to work either so perhaps I’ve done something wrong here.

[lua]

local function textListener( event )

if ( event.phase == “began” ) then

– user begins editing text field

print( event.text )

elseif ( event.phase == “ended” or event.phase == “submitted” ) then

– text field loses focus

– do something with defaultField’s text

elseif ( event.phase == “editing” ) then

if string.len(event.text) >6 then

             event.text=string.sub (event.text, 1,6)

return true

            end

end

end

– Only show input fields if level was completed

if (score_sat==score_total) then

– Create text field

input1 = native.newTextField( display.contentCenterX, display.contentCenterY, 350, 45 )

input2 = native.newTextField( display.contentCenterX, display.contentCenterY+110, 350, 45 )

– Add default values

if (username~="") then

 input1.text=username

end

if (useremail~="") then

 input2.text=useremail

end

input1:addEventListener( “userInput”, textListener )

– Setup field size/font

local inputFontSize = 18/display.contentScaleY

local tHeight = 80

input1.font = native.newFont( native.systemFontBold, inputFontSize )

input1.size = inputFontSize

input1.height=tHeight

input2.font = native.newFont( native.systemFontBold, inputFontSize )

input2.size = inputFontSize

input2.height=tHeight

end – end check if level won

[/lua]

Hi @nun_dabold1,

Thanks for the code. Are you able to replicate a crash, or only your client? Would they be able to provide you with a crash report from the console if you asked for it and they are able (and know how) to locate it?

Thanks,

Brent

Hi Brent,

 Sadly I can’t replicate it. It works in the simulator, it works in the x-code simulator although when I switch to a 64 bit device, the app just does not show up on the simulator. It also works on my Android devices as well as iPad2, iPhone4.

 Client is not very technical so I don’t think they would be able to do that, I was posting here in the hope that someone had a similar experience and had found a solution.

 As the “editing” phase isn’t working correctly, I guess I’ll try removing the listener and see if they still have issues.