Page 1 of 1

on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Aug 05, 2021 10:32 am
by stam
Hi all,

I needed some things to happen in an app before the stack is closed so thought i'd use either on closeStack, or on closeStackRequest to make this happen.

However these messages are fired off both when property inspectors are closed and when the code editor is closed - not just with the stack itself.
I know i can set a conditional

Code: Select all

if the environment is "development" then...
but then i can't test to see if what happens with my code.

This makes it unusable in the IDE and I would argue that this is not correct behaviour... or is it? I would have thought that this being in the stack's stack script, it should only affect the current stack, not the property inspectors or the code editor.

Is this is not correct behaviour i'll file a bug request - grateful for input from those more knowledgeable that me!
Stam

Re: on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Aug 05, 2021 10:47 am
by stam
After quitting liveCode a few times, this now seems to work as expected. Must have been some funny crossed wires - please ignore...

I have however run into a different problem.
I have the following code in on closeStackRequest - the idea is to do some housekeeping and if the stack is closed, the standalone should quit but not if in IDE (not an issue on Windows, but on MacOS it leaves the standalone running with no windows):

Code: Select all

on closeStackRequest 
    answer "Quit application?" with "No" or "Quit"
    if it is "Quit" then 
        -- DO STUFF HERE
        
        if the environment is not "development" then quit -- quit if standalone, not IDE
        pass closeStackRequest
    end if
end closeStackRequest
The problem is that i get the answer dialog twice when i click 'Quit' and i can't figure out why...

Re: on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Aug 05, 2021 6:03 pm
by jacque
I use CloseStackRequest only to see if the user really means to quit, and do all the real work in closeStack. If you have the same code in both places it could fire twice.

Re: on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Aug 05, 2021 6:11 pm
by SparkOut
Are there any substacks or library stacks in use?
If the app is closing then the substacks will also create stack closing messages, which will be passed up to the mainstack if they don't have their own handlers.
Assuming that is the reason, I also assume that the closeStackRequest handler is in the stack script. If you move it to the card script of card 1 then this should handle the mainstack closing message but substack triggered messages will bypass the handler and be silently eaten by the engine.

Re: on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Aug 05, 2021 10:59 pm
by stam
Thanks guys
Actually my solution runs with a hidden stack (NOT substack - in a different directory) which may well be triggering the 2nd answer dialog... but why?

Moving the on closeStackReqeust to card 1 certainly works and i only get 1 answer dialog. But then this only works for card 1... closing the stack while on any other card has no effect, so the only way this is helpful is adding this to all cards, not ideal.

however i ended up doing this anyway because on putting this handler back into the stack script, it's now reverted to the behaviour in my original post, of this being triggered by closing property inspectors and code editor, which is nuts.

If this is not normal behaviour and if others can reproduce i'll put this (see handler above) i'll submit a bug -- because it's bugging me!

Re: on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Aug 05, 2021 11:33 pm
by FourthWorld
To diagnose this you may want to give 4W Flight Recorder a try. You'll find it in LiveNet - in the IDE see Development -> Plugins -> GoLiveNet

Flight Recorder displays messages and the handler chains they trigger, in near-real time and nicely indented for easy reading.

Re: on closeStack and on closeStackRequest firing incorrectly?

Posted: Thu Dec 15, 2022 10:00 pm
by aetaylorBUSBnWt
I also see the closeStackRequest message being passed to my main Stack when closing development windows - messagebox, Project Browser, etc.

It took me forever to figure out why variables that had values in them would suddenly not have them - the code to close the application was executing just because I had closed the messagebox or some other development window. It wasn't until I put in logging messages and a field to display them that I discovered this craziness.
This is just plain wrong in all senses of the concept.
The development environment should NEVER EVER pass its stuff through the application I am developing.
And no, don't tell me I have to put checks to see if the environment is screwing with my code.
This is just a bug, plain and simple.