native.showAlert - crash

I have an application where a user “fires” a cannon by pressing a UI managed button. At the same time a timer is counting down. When the timer hits 0 a “Play Again?” showAlert is displayed.

Everything works unless the “fire” button is depressed at the moment the showAlert is launched. In such a case the app crashes after selecting “yes” on the showAlert. Once again, if the button is not depressed at the moment the showAlert launches then everything works great.

Has anyone else seen this?

Any help is greatly appreciated.
Thanks!
Tim [import]uid: 16901 topic_id: 6738 reply_id: 306738[/import]

Is anyone else using a showAlert box with an app that also has a button on the screen (e.g., fire button)? If so, I would appreciate it if you could run a test.

Please hold the button down (i.e., place finger on button) just prior to the Alertbox poping up… keep holding the button and (at the same time) press selection button on the Alertbox.

This always gives me a bus error that shutsdown the app. It’s unlikely that a user would ever do this but I don’t want to publish an app with a known problem… however unlikely it is to show up.

Thanks!
Tim [import]uid: 16901 topic_id: 6738 reply_id: 23661[/import]

Does it only happen in the simulator?

How about when you try it on the device?

I know they’re having issues with native.showAlert in the Simulator, one of which is popping consecutive alerts, like one to ask “Yes” or “No,” followed by an “Are you sure?” That really does it in for the Simulator, but it’s fine on the device.

One of the ways I got around it is by adding an insignificant timer to the alert.

[lua]performWithDelay (100, function() local alert = native.showAlert ( “Confirm”, “Are you sure?”, { “Yes”, “No” }, onComplete) end, 1)[/lua]

And, to answer your question, I use many native alerts and have tons of buttons on the screen at the same time that I’m hitting. [import]uid: 6084 topic_id: 6738 reply_id: 23669[/import]

Crashes on the phone as well.

Just thinking… would requiring multitouch help? … never really looked into what multitouch does… but I know I’m not using it.

Thanks! [import]uid: 16901 topic_id: 6738 reply_id: 23673[/import]

No, multitouch is only for the Event Listeners. I don’t have multitouch enabled in my game. Did the delay help? Can you post a snippet of your code? [import]uid: 6084 topic_id: 6738 reply_id: 23675[/import]

I’ll try the delay when I get home tonight. I’ll post the result. If still no good then I’ll put together a stripped down example code and post.

Thanks!
Tim [import]uid: 16901 topic_id: 6738 reply_id: 23677[/import]

The delay didn’t make a difference. Here is the core of the problematic code… it is a module loaded by director class. The code places a button on the screen and then counts down from 7. If you press the button and hold it while the Alert pops up… and then hit the RETURN key to simulate simultaneous selection of YES… it crashes. This crashes in both the simulator and on a iphone 3GS.

Any ideas? Thanks!

[code]
module(…, package.seeall)

– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()

local gameOver=0
local gameTime=0
local gameDuration=7
local score=11
– display timer text on screen
local textObject = display.newText( “0”, 100, 30, “Courier”, 20 )
textObject:setTextColor( 255,215,175 )
textObject:setReferencePoint(display.CenterLeftReferencePoint)
localGroup:insert(textObject)
textObject.text ="SHOT CLOCK: "…gameDuration-gameTime
local timeCheck = {}
function timeCheck:timer( event )
gameTime=gameTime+1
if (gameDuration-gameTime)>=10 then
textObject.text ="SHOT CLOCK: "…gameDuration-gameTime
end
if (gameDuration-gameTime)<10 then
textObject.text =“SHOT CLOCK: 0”…gameDuration-gameTime
end

if ( gameDuration-gameTime==0 ) then
timer.cancel(t2)
playAgain()
end
end

– start timer
t2 =timer.performWithDelay(1000, timeCheck, 0)

– ####### BUTTON PRESS HANDLER #######

local mainButtonHandler = function( event )
------enter code here ----
end
– Define Main Button
local buttonMain = ui.newButton{
default = “images/button_2.png”,
over = “images/button_1.png”,
onEvent = mainButtonHandler,
id = “pushbutton”,
text = “Press”,
size = 30,
textColor = { 255, 255, 255, 255 },
emboss = true
}

buttonMain.x = (display.contentWidth / 2)-2
buttonMain.y = 440
localGroup:insert(buttonMain)
– ####### PLAY AGAIN? #######
local function onComplete( event )

if “clicked” == event.action then
if 2 == event.index then
unloadThenMenu()
end
if 1 == event.index then
unloadThenReplay()
end
end
end
playAgain = function()
gameOver=1
print(“PLAY AGAIN”)
– show alert
if score~=0 then
print(“PLAY AGAIN”)
local alert = native.showAlert( “You made baskets in “…gameDuration…” seconds!”, “Play Again?”, { “YES”, “NO” }, onComplete )
print(“PLAY AGAIN”)
else
local alert = native.showAlert( “Good Try!”, “Play Again?”, { “YES”, “NO” }, onComplete )
end
print(“PLAY AGAIN”)
end

– ####### UNLOAD & RE-PLAY #######
unloadThenReplay = function()

– REMOVE EVENT LISTENERS

– REMOVE everything in other groups
for i = localGroup.numChildren,1,-1 do
local child = localGroup[i]
child.parent:remove( child )
child = nil
end

director:changeScene(“game_shot_clock_loader”)
end

– ####### UNLOAD & BACK TO MENU #######
unloadThenMenu = function()

– REMOVE EVENT LISTENERS

– REMOVE everything in other groups
for i = localGroup.numChildren,1,-1 do
local child = localGroup[i]
child.parent:remove( child )
child = nil
end

director:changeScene(“game_menu”)
end [import]uid: 16901 topic_id: 6738 reply_id: 23734[/import]

can you zip this up with the right images etc and send it to me to take a gander at

[import]uid: 24 topic_id: 6738 reply_id: 23781[/import]

I’ve submitted a “bug” report with the files. If you want me to send directly to you then please tell me how I can send you an email… I don’t see a “respond directly” link… Thanks! - Tim [import]uid: 16901 topic_id: 6738 reply_id: 23789[/import]

cicaza @ anscamobile . com

c [import]uid: 24 topic_id: 6738 reply_id: 23790[/import]

email sent… thanks so much for taking a look. [import]uid: 16901 topic_id: 6738 reply_id: 23792[/import]

fyi… fixed via build 302. Thanks Carlos! [import]uid: 16901 topic_id: 6738 reply_id: 23864[/import]