Handler repeats itself 2-3 or more times

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Handler repeats itself 2-3 or more times

Post by kresten » Tue Jun 21, 2011 12:41 am

Hi
I am trying to debug an annoying error : one handler, in a app 2500 lines substack script, returns, after its end (in one version via a particular line 3 in the script, even when that line is empty) and insists repeating itself at least 2 time, sometimes 3 times and even more. The problem persists both in windows version and in mac version.
Does this sound as a phenomenon others have encountered ?

on phenoupdate
global phenodate,term
set the twelvehourtime to false
set the usesystemdate to true
put the seconds into sekundkasse
convert sekundkasse to dateitems
put item 4 of sekundkasse into trueHour
put item 5 of sekundkasse into trueMinute
put the date into datokasse
convert datokasse to dateitems
if the number of chars of item 2 of datokasse = 1 then
put "0" before item 2 of datokasse
end if
if the number of chars of item 3 of datokasse = 1 then
put "0" before item 3 of datokasse
end if
put char 3 to 4 of item 1 of datokasse into phenodate
put item 2 of datokasse after phenodate
put item 3 of datokasse after phenodate
set itemdelimiter to ":"
put item 1 of the maketime of this stack into chooseHour
put item 2 of the maketime of this stack into chooseMinute
if phenodate is not the lastmadecard of this stack then
if trueHour > chooseHour and trueMinute > chooseMinute then
nytkort
end if
if the seconds > field "daysecond" + 104400 then
nytkort
end if
end if
if the stillexamples of this stack is false then
delete field "justexamples"
end if
save stack "e-diary"
put return & the time after field "lastsavedField" of stack "Phenomenalog"
put the updaterate of stack "Phenomenalog" into term
send "phenoupdate" to stack "Phenomenalog" in term seconds
select after text of field "TextField" of stack "Phenomenalog"
end phenoupdate

Hoping for rescue
Kresten

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Re: Handler repeats itself 2-3 or more times

Post by SparkOut » Tue Jun 21, 2011 1:08 am

I haven't studied your script in any real detail but I couldn't see anything obvious that should produce the odd behaviour you describe.

Where do you have you handler located in the project? You said that the handler is part of a substack script, but is it invoked from anywhere else? I can only guess, but my suspicion is tending towards that you may have a mainstack with substacks that you open and close at different points?
In the mainstack script is there a call to your phenoupdate handler in an openStack or closeStack handler?
If so, do you have an openStack or closeStack handler in the stack script of *every* substack in the project? If not then as a substack is opened or closed the message will pass up to the mainstack handler and be caught there, regardless of whether you wanted it to or not. You would need to put an empty openStack or closeStack handler without passing the message in the script of each substack in order for the message not to go up through the stack hierarchy and reach the mainstack handler.
If your "nytkort" handler is callled from your phenoUpdate handler then does it maybe create a new substack? Which would then generate an openStack message that passes up to the mainstack and from there may trigger another call to the phenoUpdate handler?
I don't know, of couse, I am only guessing and I may be way of the target but it's the best idea I can think of at the moment.


PS, I will delete my reply in the "Windows" section so that you can remove the question from there too.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Handler repeats itself 2-3 or more times

Post by dunbarx » Tue Jun 21, 2011 3:58 am

Can you put a breakpoint in the beginning of the handler, and then try to track what happens whenever it is called again? I agree with SparkOut's theory, that the handler is being re-called very explicitly, though in a non-obvious way.

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by jacque » Tue Jun 21, 2011 4:17 am

put the updaterate of stack "Phenomenalog" into term
send "phenoupdate" to stack "Phenomenalog" in term seconds
It looks like it is calling itself at the end.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Handler repeats itself 2-3 or more times

Post by Klaus » Tue Jun 21, 2011 12:49 pm

Kresten,

only one thread for one topic, please!
Will delete your (same) posting from the "Windows" section.

Best

Klaus

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by kresten » Wed Jun 22, 2011 3:28 pm

Hi
Sorry for the mistaken double posting.
I have been trying the tracking many many times, but the return to same handler just occurred ... and presently somehow it has changed so the repetition only occurs 3 times, but with one to two minutes interval. The handler is only called from 2 places: a button on the main stack, and a menuitem in the same substack. Called from the menuitem only one saving occurs.
To jacqueline: yes, the essense is, that it calls itself after a user-defined saving interval.
Yes, there are 19 substacks, but none of the others have any reference to the phenoupdate handler.
I am ending up in a situation where I felt it necessary to attach the full mainstack here, in the hope, that one of you could have a closer look at the problem, but size limit of 2 MB here , and even zipped it is a little more.
Strange problems came up with downloadability of a version placed on rev-online, and when I removed that and tried to upload a new version other unexplicable errors prevented that !!!!!
I then decided to put it as zipped downloadable file in http://www.phenomenalog.dk, - but hit upon another obstacle: that the host had made changes to their server, and will have to move the site to another server,- they promised to do this tomorrow, I will return and report here, when it is available.
So long
Kresten

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by Mark » Fri Jun 24, 2011 9:52 am

Hi Kresten,

Put this before the line with the "send" command and let me know if it helps:

Code: Select all

set the itemDel to comma
put the pendingMessages into myMessages
repeat for each line myLine in myMessages
  if myLine contains "phenoUpdate" then -- (typo corrected)
    cancel item 1 of myLine
  end if
end repeat
Kind regards,

Mark
Last edited by Mark on Mon Aug 08, 2011 9:22 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by kresten » Fri Jun 24, 2011 11:39 am

Thank you, Mark. I tried it, result is: 2 consecutive savings
I suceeded - after the webhost's admitting an unannounced change, and repairing - to upload a zipped version (before Marks lines were included) of the mainstack to www.phenomenalog.dk/downloads , where you can click "e-diary.rev" link to download it.
. OBS: the stack assumes a context of folders, so its new card (nytkort) function and other functions may produce error, - and the absence of the 12 special fonts make it look strange, but I guess it should be apt for debugging of the repetitive saving.
I shall be most thankfull if one of you can help
best regards
Kresten

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by Mark » Fri Jun 24, 2011 11:44 am

Hi Kresten,

You tried it... and did it help?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by kresten » Fri Jun 24, 2011 12:59 pm

Because the stack somehow had ended by making 3 savings, and even with a minutes interval, - and after the insertion returned to the simple 2-savings - you can say, that it helped -but evidently doesnt solve the essential error. :( :(
but thank you for trying
best regards
kresten

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Handler repeats itself 2-3 or more times

Post by sturgis » Sun Jul 31, 2011 2:50 pm

Mark wrote:Hi Kresten,

Put this before the line with the "send" command and let me know if it helps:

Code: Select all

set the itemDel to comma
put the pendingMessages into myMessages
repeat for each line myLine in myMessages
  if myLine contains phoneUpdate then 
[i]--[b]If you tried this with a copy paste, try it again changing it to phenoUpdate, I read it 5 times before noting the difference[/b][/i]
    cancel item 1 of myLine
  end if
end repeat
Kind regards,

Mark

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by Mark » Sun Jul 31, 2011 2:59 pm

Hi,

Oops! Sorry, I didn't notice this myself. Sometimes my fingers don't listen to my brain and just type by themselves :-)

PhoneUpdate should indeed be PhenoUpdate. Thanks for pointing that out.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: Handler repeats itself 2-3 or more times

Post by kresten » Sun Jul 31, 2011 10:34 pm

I saw a new live code video, presented at bjørnke and Mark schonewilles weekly Saturday night event: Claudi Cornaz told and demonstrated a new stack-analyzer tool: StackAlly, and I mailed and asked him if he could use his tool to solve the mystery of repeated savings in phenomenalog.
He did.
Here is extract of his reply:
…..It looks like nytkort first sends "phenoupdate" and next in the end of the phenoUpdate it get's send again and then in the nytkort it gets send again etc.
My sugestion would be to check if phenoUpdate is already in the pendingMessages. If so don't send it again or first
cancle the one that already is there and then send the 'new' one.

if lineOffset(comma & "phenoUpdate" & comma, the pendingMessages) = 0 then send "phenoupdate" to stack "Phenomenalog" in term seconds
use this both in the "phenoUpdate" and the "nytkort" handler.

Try this to see if it helps. The way it is now it realy looks like a recursion, which isn't intended, I guess.

Hope it helps. Let me know, so if it doesn't I can take another look.

All the best,
Claudi

I replied

Dear Claudi

Hurrah !!!!!! Hurrah !!!!!! Hurrah !!!!!!
It works !

Thanks for all efforts
Kresten

Post Reply