on closeStack and on closeStackRequest firing incorrectly?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

on closeStack and on closeStackRequest firing incorrectly?

Post by stam » Thu Aug 05, 2021 10:32 am

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

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: on closeStack and on closeStackRequest firing incorrectly?

Post by stam » Thu Aug 05, 2021 10:47 am

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...

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: on closeStack and on closeStackRequest firing incorrectly?

Post by jacque » Thu Aug 05, 2021 6:03 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: on closeStack and on closeStackRequest firing incorrectly?

Post by SparkOut » Thu Aug 05, 2021 6:11 pm

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.

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: on closeStack and on closeStackRequest firing incorrectly?

Post by stam » Thu Aug 05, 2021 10:59 pm

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!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: on closeStack and on closeStackRequest firing incorrectly?

Post by FourthWorld » Thu Aug 05, 2021 11:33 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Thu Sep 20, 2012 5:11 pm

Re: on closeStack and on closeStackRequest firing incorrectly?

Post by aetaylorBUSBnWt » Thu Dec 15, 2022 10:00 pm

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.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”