Clock sample app freezes

The sample clock app running on real platform (ipod touch) freezes after around an hour. I’ve some code based on that sample that also freezes after a while, so I guess it’s something in the clock sample app that is having some sort of memory free/reuse type issue. Anyway can’t release my app do to this freezing, sample clock seems to work fine on simulator without freezing. Is there a way to generate log info on touch?

Regards
Andrew Wilson [import]uid: 3867 topic_id: 623 reply_id: 300623[/import]

Even modified sample clock freezes after about an hour running on my ipod touch.

Seems to be some problem with
local clockTimer = timer.performWithDelay( 1000, updateTime, -1 )

after about 3600 calls no more calls are made to updateTime. But orientation still works.

Below is modified sample with os.time performed only once…

Any feedback welcome??

– Abstract: Orientation sample app, with digital clock
– …comment stuff…
– Copyright © 2010 ANSCA Inc. All Rights Reserved.

– display.setStatusBar( display.HiddenStatusBar )

local clock = display.newGroup()

local background = display.newImage( “purple.png” )
clock:insert( background, true )
background.x = 160; background.y = 240

– Set the rotation point to the center of the screen
clock:setReferencePoint( display.CenterReferencePoint )

– Create dynamic textfields
local hourField = display.newText( “”, 0, 0, “Arial-BoldMT”, 180 )
hourField:setTextColor( 255, 255, 255, 70 )
clock:insert( hourField, true )
hourField.x = 100; hourField.y = 90; hourField.rotation = -15

local minuteField = display.newText( “”, 0, 0, “Arial-BoldMT”, 180 )
minuteField:setTextColor( 255, 255, 255, 70 )
clock:insert( minuteField, true )
minuteField.x = 100; minuteField.y = 240; minuteField.rotation = -15

local secondField = display.newText( “”, 0, 0, “Arial-BoldMT”, 180 )
secondField:setTextColor( 255, 255, 255, 70 )
clock:insert( secondField, true )
secondField.x = 100; secondField.y = 390; secondField.rotation = -15

– Create captions
local hourLabel = display.newText( "hours ", 0, 0, “Zapfino”, 40 )
hourLabel:setTextColor( 131, 255, 131, 255 )
clock:insert( hourLabel, true )
hourLabel.x = 240; hourLabel.y = 100

local minuteLabel = display.newText( "minutes ", 0, 0, “Zapfino”, 40 )
minuteLabel:setTextColor( 131, 255, 131, 255 )
clock:insert( minuteLabel, true )
minuteLabel.x = 240; minuteLabel.y = 250

local secondLabel = display.newText( "seconds ", 0, 0, “Zapfino”, 40 )
secondLabel:setTextColor( 131, 255, 131, 255 )
clock:insert( secondLabel, true )
secondLabel.x = 230; secondLabel.y = 400

– only get time once
local time = os.date("*t")
local secondText = 0

local function updateTime()

local hourText = time.hour
if (hourText < 10) then hourText = “0” … hourText end
hourField.text = hourText

local minuteText = time.min
if (minuteText < 10) then minuteText = “0” … minuteText end
minuteField.text = minuteText

if secondText == 0 then
secondText=1
else
secondText=0
end

secondField.text = secondText
if (secondText < 10) then secondField.text = “0” … secondField.text end
end

updateTime() – run once on startup, so correct time displays immediately
– Update the clock once per second
local clockTimer = timer.performWithDelay( 1000, updateTime, -1 )
– Use accelerometer to rotate display automatically
local function onOrientationChange( event )

– Adapt text layout to current orientation
local direction = event.type

if ( direction == “landscapeLeft” or direction == “landscapeRight” ) then
hourField.y = 120
secondField.y = 360
hourLabel.y = 130
secondLabel.y = 370
elseif ( direction == “portrait” or direction == “portraitUpsideDown” ) then
hourField.y = 90
secondField.y = 390
hourLabel.y = 100
secondLabel.y = 400
end

– Rotate clock so it remains upright
local newAngle = clock.rotation - event.delta
transition.to( clock, { time=150, rotation=newAngle } )
end

Runtime:addEventListener( “orientation”, onOrientationChange ) [import]uid: 3867 topic_id: 623 reply_id: 1276[/import]

This simple app stops counting after about an hour or 11644 tics one tic every quarter of second on my ipod touch, Shouldn’t this code count forever??? Can anyone see similar problem on there device build???

Thanks
Andrew Wilson


– infinite timed count

system.setIdleTimer( false ) – turn off device sleeping

local counter=0
local countField = display.newText( tostring(counter), 250, 190, “Arial-BoldMT”, 24 )
countField:setTextColor( 255, 255, 255 )

local function updateCount()
counter=counter+1
countField.text = tostring(counter)
end

local clockTimer = timer.performWithDelay( 250, updateCount, -1 )
[import]uid: 3867 topic_id: 623 reply_id: 1288[/import]

Another run stops at 11645 ticks, this seems to be an really real issue, Feedback? [import]uid: 3867 topic_id: 623 reply_id: 1289[/import]

Its in the test queue to see why it fails after 11,645 ticks.

Carlos [import]uid: 24 topic_id: 623 reply_id: 1290[/import]

great, thanks. AGRW [import]uid: 3867 topic_id: 623 reply_id: 1292[/import]

(Logged as bug #139) [import]uid: 3 topic_id: 623 reply_id: 2045[/import]

Here is my modified timer code that stops after 2880 counts (12 minutes). The timer fires every 0.250 seconds. The code has been modified to cancel and restart the timer every 5 minutes (1200 counts).

Note: The counter stopped at the same count before I added the timer restart.

--  
-- infinite timed count  
--  
-- Corona bug #139 - test code  
  
system.setIdleTimer( false ) -- turn off device sleeping  
  
local counter=0  
  
local clockTimer  
  
local countField = display.newText( tostring(counter), 200, 190, "Arial-BoldMT", 36 )  
countField:setTextColor( 255, 255, 255 )  
  
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
local function updateCount()  
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
counter=counter+1  
countField.text = tostring(counter)  
  
 -- Restart timer every 5 minutes  
 if ((counter % 1200) == 0) then  
 timer.cancel( clockTimer )  
 print "Timer restarted"  
 clockTimer = timer.performWithDelay( 250, updateCount, 0 )  
 end  
  
end -- updateCount  
  
clockTimer = timer.performWithDelay( 250, updateCount, 0 )  

This counter should run forever so the question is why does it stop after 2880 counts? It was tested with Corona 2.0 Beta 3 on a 3GS iPhone (v3.1.3).

Tom
[import]uid: 6119 topic_id: 623 reply_id: 2597[/import]

Here is an update to this bug.

I tested the code under Beta 5 and the timer still stops around count 2880 at 13 minutes into the test.

I changed the timer from 250 msec. to 500 msec. and now the count stops around 1517 – also at 13 minutes into the test. The count varies from test to test but the time at when it stops seems very consistence.

I was looking at the Xcode Console Output and Instruments (Leak) and they both showed the program was still running when the counter stopped. (This was on an iPhone 3GS running 3.1.4).

It seems the bug (timer stops firing) is time related (13 minutes) and not dependent on the time delay value.

I hope this helps narrow down the problem.

Tom [import]uid: 6119 topic_id: 623 reply_id: 3173[/import]

THANKS for this thread! I was able to adapt your code into a countdown timer that was much more reliable than the one I was using. [import]uid: 124116 topic_id: 623 reply_id: 87771[/import]