iT2D 1.5 Final getiPhoneKeyboardInput Crash Bug (ITGB-295)
by Craig Jorgensen · in iTorque 2D · 11/04/2011 (5:44 am) · 3 replies
Hi,
There appears to be a bug with the iPhone keyboard input popup which causes it to crash (passes a null pointer to strcpy).
Seems easy enough to replicate, create a button that calls getiPhoneKeyboardInput. It works the first time you call it and enter your text, but if you click the button a second time it will crash.
ConsoleFunction(getiPhoneKeyboardInput, const char *, 2, 2, "getiPhoneKeyboardInput(textToUse) Returns a string of text from the iPhone OS keyboard")
{
argc; argv;
StringBuffer mTextBuffer = argv[1];
bool cancelled = !iPhoneTextEntry::getUserText(mTextBuffer);
const char *retrn = argv[1];
if(cancelled)
{
//If they cancelled, return what they passed in as the "textToUse"
Con::setVariable("$iPhone::keyboardWasCancelled", "1" );
}
else
{
//If they didnt cancel, return the results of their entry
char *ret = Con::getReturnBuffer(mTextBuffer.length());
dStrcpy(ret, mTextBuffer.getPtr8()); <-----------------------------------
Con::setVariable("$iPhone::keyboardWasCancelled", "0" );
return ret;
}
Re the line marked with arrow "dStrcpy(ret, mTextBuffer.getPtr8());",
When the getiPhoneKeyboardInput is called the second time, mTextBuffer.getPtr8() returns a null pointer. dStrCpy then calls strcpy with a null ptr causing a crash.
@Michael, could you please take a look at this and let me know how to patch it to resolve the problem. I had just compiled in release mode and was going to run through a last lot of testing before releasing the app and this came up.
On a related note, i noticed that when switching from iT2D 1.5 preview 2 to the 1.5 final release, the returned params of callback for this function had changed their order.
In 1.5 Final, param order seems to be oniPhoneKeyboardInputFinished(%text,%cancelled,%notsure)
In 1.5 Prev2, param order seems to be oniPhoneKeyboardInputFinished(%notsure,%cancelled,%text)
%text is the user entered text
%cancelled is whether the form was cancelled
%notsure is a param that doesnt seem to return anything, not sure what it does
Considering the iPhoneTextEntry.mm file hasnt changed between those versions, something rather strange must be going on for the param order to have changed.
Thanks in advance
Craig
There appears to be a bug with the iPhone keyboard input popup which causes it to crash (passes a null pointer to strcpy).
Seems easy enough to replicate, create a button that calls getiPhoneKeyboardInput. It works the first time you call it and enter your text, but if you click the button a second time it will crash.
ConsoleFunction(getiPhoneKeyboardInput, const char *, 2, 2, "getiPhoneKeyboardInput(textToUse) Returns a string of text from the iPhone OS keyboard")
{
argc; argv;
StringBuffer mTextBuffer = argv[1];
bool cancelled = !iPhoneTextEntry::getUserText(mTextBuffer);
const char *retrn = argv[1];
if(cancelled)
{
//If they cancelled, return what they passed in as the "textToUse"
Con::setVariable("$iPhone::keyboardWasCancelled", "1" );
}
else
{
//If they didnt cancel, return the results of their entry
char *ret = Con::getReturnBuffer(mTextBuffer.length());
dStrcpy(ret, mTextBuffer.getPtr8()); <-----------------------------------
Con::setVariable("$iPhone::keyboardWasCancelled", "0" );
return ret;
}
Re the line marked with arrow "dStrcpy(ret, mTextBuffer.getPtr8());",
When the getiPhoneKeyboardInput is called the second time, mTextBuffer.getPtr8() returns a null pointer. dStrCpy then calls strcpy with a null ptr causing a crash.
@Michael, could you please take a look at this and let me know how to patch it to resolve the problem. I had just compiled in release mode and was going to run through a last lot of testing before releasing the app and this came up.
On a related note, i noticed that when switching from iT2D 1.5 preview 2 to the 1.5 final release, the returned params of callback for this function had changed their order.
In 1.5 Final, param order seems to be oniPhoneKeyboardInputFinished(%text,%cancelled,%notsure)
In 1.5 Prev2, param order seems to be oniPhoneKeyboardInputFinished(%notsure,%cancelled,%text)
%text is the user entered text
%cancelled is whether the form was cancelled
%notsure is a param that doesnt seem to return anything, not sure what it does
Considering the iPhoneTextEntry.mm file hasnt changed between those versions, something rather strange must be going on for the param order to have changed.
Thanks in advance
Craig
About the author
Recent Threads
#2
The problem is that you cant pass an empty string in the getiPhoneKeyboardInput (if you dont want any default text) as the code is set to use that param as the string buffer for user entry. The code in the iPhoneTextEntry.mm seems a bit silly as trys to return the 'user input' from the initial call, but the string is actually returned via the callback, so i presume its some left over legacy code from a previous implementation of this function.
The actual popup window also doesn't display properly on retina display, the cancel button moves off screen and the entry text box resizes to be wider than the screen. All in all, this functionality just needs to be redone properly in later version of iTGB. The problem with the resizing is due to the iPhoneTextEntry.mm manually resizing the view to the retina display resolution (640x960 portrait), however iOS seems to want the window size in non-retina dimensions even when using a retina display. So if the resize code is changed to set the window size to 320x480 (portrait) when using retina display it works fine. For non-retina and ipad, there proper resolutions are fine to use.
11/14/2011 (2:09 am)
I have figured out more on the cause of thisThe problem is that you cant pass an empty string in the getiPhoneKeyboardInput (if you dont want any default text) as the code is set to use that param as the string buffer for user entry. The code in the iPhoneTextEntry.mm seems a bit silly as trys to return the 'user input' from the initial call, but the string is actually returned via the callback, so i presume its some left over legacy code from a previous implementation of this function.
The actual popup window also doesn't display properly on retina display, the cancel button moves off screen and the entry text box resizes to be wider than the screen. All in all, this functionality just needs to be redone properly in later version of iTGB. The problem with the resizing is due to the iPhoneTextEntry.mm manually resizing the view to the retina display resolution (640x960 portrait), however iOS seems to want the window size in non-retina dimensions even when using a retina display. So if the resize code is changed to set the window size to 320x480 (portrait) when using retina display it works fine. For non-retina and ipad, there proper resolutions are fine to use.
#3
11/21/2011 (5:04 pm)
logged as ITGB-295
Craig Jorgensen
Pocket Playground
Any ideas on the problem?