Page 1 of 1

Application restarts after quiting

Posted: Sun Jan 12, 2014 6:27 pm
by andyt
I've created a small app that is based on the RunRev slideshow example that uses images imported onto card backgrounds as controls. My problem is that when the application is closed (using the window 'X' icon) while an image transition is actually in progress the application closes and immediately reopens. I've spent all afternoon playing with the code to no avail. Why is this happening and how do I successfully exit the app at all times?

Code: Select all

local sMessageID ## stores the message ID so we can stop the background changing

on openCard 
   ## executed every time we go to a new card
   ## the slideshow begins when openCard is executed
   ## delay 2 seconds, then go to the next card
   send "showNextSlide" to me in 2 seconds
   
   ## store the ID of the delayed message you just sent, so
   ## you can cancel it if the user clicks pause
   put the result into sMessageID
end openCard

on closeStack 
   quitMyProject
end closeStack

on mouseUp
## when the user clicks
if "showNextSlide" is among the items of the pendingMessages then
## stop the slideshow
   cancel sMessageID
else 
## restart the slideshow
   showNextSlide
end if
end mouseUp

on showNextSlide
   visual effect "dissolve fast"
   go next card 
   ## which will trigger the openCard handler
end showNextSlide

command quitMyProject
   cancel sMessageID
   lock messages
   -- stop using stacks
   put the stacksInUse into myStacks
   repeat for each line myStack in myStacks
      stop using stack myStack
   end repeat
   -- stacks
   put the openStacks into myStacks
   put "message box,home,tool,Message Box,revTools,revMenubar" & comma & the short name of me into myDontClose
   repeat for each line myStack in myStacks
      if myStack is not among the items of myDontClose then close stack myStack
   end repeat
   -- messages
   put the pendingmessages into myMsgs
   repeat for each line myMsg in myMsgs
      cancel item 1 of myMsg
   end repeat
   close me
   if the environment is not "development" then
      quit
   end if
end quitMyProject
I also have another issue which only occurs when the application window is resized using the 'maximize' button during an image transition. The image below shows what happens:
resize-issue.jpg

Re: Application restarts after quiting

Posted: Mon Jan 13, 2014 4:26 am
by Simon
Hi Andy,
I'm thinking this has to do with the "go next card" and the dissolve.
It doesn't show up in the pending messages so trying to cancel it doesn't work.

I think you can use "on closeStackRequest" to wait until an openCard.
Put a boolean into the openCard and reverse it on closeCard
Don't forget to "pass closeStackRequest".

Simon

Re: Application restarts after quiting

Posted: Mon Jan 13, 2014 5:32 am
by Simon
Hi Andy,
I've been thinking about this some more.
Visual effect uses quicktime, I think this is where the problem is (it never used to crash but now I see it does).
Better if you use the blendLevel method then you don't need your users to have qt installed.The dissolve effect is horrible on machine w/o qt.

So, place all your images on one card and name them sequentially (e.g. picture1,picture2...)

Code: Select all

local tCount = 0
local sCount = 1
on mouseUp
   add 1 to tCount
   add 1 to sCount
   repeat with x = 1 to 100 with messages
      set the blendLevel of img ("picture" & tCount) to x
      set the blendLevel of img ("picture" & sCount) to (100-x)
      wait 10 milliseconds with messages
   end repeat
   if tCount >=3 then put 0 into tCount --I used 3 images, this should be the number of images you have
   if sCount >=3 then put 0 into sCount --same as above
   send mouseUp to me in 2 seconds --this is where cancel pendingMessages works
end mouseUp
Now that is not well thought out but it does work.
Run it once through all the images and you'll be left with 1 image showing and the transition should be the same as you want.
Now use that cancel pendingMessages when you shut down.


Simon
Edit: for the resizing look up "resizeStack"
then set the width and height of the image to some ratio of the stack width and height (no knowing if screen is 4:3, 16:9 other?)

Re: Application restarts after quiting

Posted: Mon Jan 13, 2014 10:57 pm
by andyt
Many thanks for spending some time on this Simon. I will give it a try when I get some free time and report back. I didn't imagine that visual effects relied on Quicktime.