Lost or slow messages resulting in partial redraw of card.

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Lost or slow messages resulting in partial redraw of card.

Post by Simon Knight » Sun Feb 28, 2021 10:26 am

Hi,

I'm on a Mac running Big Sur and Livecode Indy 9.6.1 and the problem described occurs in the IDE.

I have a project that is a stack with two cards "Main" and "Settings". Card "Main" has what is a complex list based custom control which came from Scott Rossi's web site. This control uses a behaviour button which is stored in a separate Stack named Behaviours. One of the handlers in the behaviour button updates the custom control and this update handler gets called from the open card handler via a default settings handler on the card. The settings card has no handlers that are called when it is closed.

The custom control is named "ListOfShoots" so the calling chain is:

On Opencard calls "EmptyListOfShoots" which is a handler on the card.

On EmptyListShoots sends "updateMyAppearance" to field "ListOfShoots"

Field "listOfShoots" runs the handler which is in its behaviour button.
This triggers multiple calls of handlers within the behaviour button which are called to make settings on every row used in the list. Typically there are between one and nine rows but the default is three.

This all sounds complex but it is a quite common structure and no different to how a datagrid is implemented. Also this structure has worked for months but recently a problem became apparent.

When switching from the settings card back to the main card the display of the main card has started to freeze with the main card only partially drawn or visible on my screen. I believe I captured a screen shot of the situation but the resulting image shows the card fully drawn.

There is a simple solution as the issue disappears if I add a line "wait 1 milliseconds with messages" in the opencard handler. However I am concerned that this fix is hiding a more complex problem.

Also I have noticed some other issues when in the IDE : some code changes I make to my code do not always stick also from time to time the line numbers stop scrolling with the code.

So is my code breaking the IDE or is the IDE breaking my code and why does a 1 millisecond delay seem to solve the card redraw issue?

Any ideas ?

I'm sure someone will ask for the code so here goes:

Code: Select all

on opencard
   wait 1 milliseconds with messages
   EmptyListOfShoots
end opencard
From the cardscript of card being opened:

Code: Select all

On EmptyListOfShoots
   put "-,-,Please select a Source Folder" & CR & "-,-,of images to rename and copy" & CR & "-,-, to folder chosen above. " into tListOfShootDates
   replace comma with tab in tListOfShootDates
   put tListOfShootDates into field "ListofShoots"
   put 3 into tRowCount
   
   # Resize the list
   put the textheight of field "ListOfShoots" into tLineHt
   put the uTablePadding of field "ListOfShoots" into tpadding
   put (2 * tPadding)+ tLineHt into tRowHt
   put tRowCount * tRowHt into tHeightOfTable
   put the top of field "ListOfShoots" into tTop
   
   set the top of field "ListOfShoots" to tTop 
   set the vscrollbar of field "ListOfShoots" to False
   send "updateMyAppearance" to field "ListOfShoots"
end EmptyListOfShoots
From the behaviour button of the listcontrol on the card being opened:

Code: Select all

command updateMyAppearance
   lock screen
   repeat with N = 1 to number of lines of me
      if N = (the hilitedLine of me) then
         set the hiliteColor of me to myHiliteColor()
         set backColor of line N of me to myHiliteColor()
         set textColor of line N of me to myHilitedTextColor()
         next repeat
      end if
      set textColor of line N of me to myTextColor()
      if N mod 2 <> 0 then
         set backColor of line N of me to myOddRowColor()
      else set backColor of line N of me to myEvenRowColor()
   end repeat
   set padding of line 1 to -1 of me to myPadding()
   set borderColor of me to mySeparatorColor()
   set vGrid of me to myShowSeparators()
   set textHeight of me to myLineHeight()
   unlock screen
end updateMyAppearance

Here is all of the code in the behaviour button, but this has worked for months in this project and in others.

Code: Select all

before mouseEnter
   put false into allowTracking
end mouseEnter


before mouseDown
   updateMyAppearance
   put true into allowTracking
end mouseDown


before mouseMove X,Y
   if not allowTracking then exit mouseMove
   updateMyAppearance
end mouseMove


before mouseUp
   put false into allowTracking
end mouseUp


before mouseRelease
   put false into allowTracking
end mouseRelease


command updateMyAppearance
   lock screen
   repeat with N = 1 to number of lines of me
      if N = (the hilitedLine of me) then
         set the hiliteColor of me to myHiliteColor()
         set backColor of line N of me to myHiliteColor()
         set textColor of line N of me to myHilitedTextColor()
         next repeat
      end if
      set textColor of line N of me to myTextColor()
      if N mod 2 <> 0 then
         set backColor of line N of me to myOddRowColor()
      else set backColor of line N of me to myEvenRowColor()
   end repeat
   set padding of line 1 to -1 of me to myPadding()
   set borderColor of me to mySeparatorColor()
   set vGrid of me to myShowSeparators()
   set textHeight of me to myLineHeight()
   unlock screen
end updateMyAppearance


# HILITED LINE
setProp hilitedTableRow pValue
   lock screen
   set hilitedLine of me to pValue
   updateMyAppearance
   unlock screen
end hilitedTableRow

getProp hilitedTableRow
   return hilitedLine of me
end hilitedTableRow


# TEXT COLOR
setProp tableTextColor pValue
   set the uTableTextColor of me to pValue
   updateMyAppearance
end tableTextColor

getProp tableTextColor
   return myTextColor()
end tableTextColor

function myTextColor
   return the uTableTextColor of me
end myTextColor


# ODD ROW COLOR
setProp tableOddRowColor pValue
   set the uTableOddRowColor of me to pValue
   updateMyAppearance
end tableOddRowColor

getProp tableOddRowColor
   return myOddRowColor()
end tableOddRowColor

function myOddRowColor
   return the uTableOddRowColor of me
end myOddRowColor


# EVEN ROW COLOR
setProp tableEvenRowColor pValue
   set the uTableEvenRowColor of me to pValue
   updateMyAppearance
end tableEvenRowColor

getProp tableEvenRowColor
   return myEvenRowColor()
end tableEvenRowColor

function myEvenRowColor
   return the uTableEvenRowColor of me
end myEvenRowColor


# HILITED LINE COLOR
setProp tableHiliteColor pValue
   set the uTableHiliteColor of me to pValue
   updateMyAppearance
end tableHiliteColor

getProp tableHiliteColor
   return myHiliteColor()
end tableHiliteColor

function myHiliteColor
   return the uTableHiliteColor of me
end myHiliteColor


# HILITED TEXT COLOR
setProp tableHilitedTextColor pValue
   set the uTableHilitedTextColor of me to pValue
   updateMyAppearance
end tableHilitedTextColor

getProp tableHilitedTextColor
   return myHilitedTextColor()
end tableHilitedTextColor

function myHilitedTextColor
   return the uTableHilitedTextColor of me
end myHilitedTextColor


# SEPARATOR COLOR
setProp tableSeparatorColor pValue
   set the uTableSeparatorColor of me to pValue
   updateMyAppearance
end tableSeparatorColor

getProp tableSeparatorColor
   return mySeparatorColor()
end tableSeparatorColor

function mySeparatorColor
   return the uTableSeparatorColor of me
end mySeparatorColor


# SEPARATOR VISIBILITY
setProp tableShowSeparators pValue
   set the uTableShowSeparators of me to pValue
   updateMyAppearance
end tableShowSeparators

getProp tableShowSeparators
   return myShowSeparators()
end tableShowSeparators

function myShowSeparators
   return the uTableShowSeparators of me
end myShowSeparators


# TEXT SHIFT VALUE
setProp tableTextShift pValue
   set the uTableTextShift of me to pValue
   updateMyAppearance
end tableTextShift

getProp tableTextShift
   return myTextShift()
end tableTextShift

function myTextShift
   return the uTableTextShift of me
end myTextShift


# PADDING
setProp tablePadding pValue
   set the uTablePadding of me to pValue
   updateMyAppearance
end tablePadding

getProp tablePadding
   return myPadding()
end tablePadding

function myPadding
   return the uTablePadding of me
end myPadding


# LINE HEIGHT
setProp tableLineHeight pValue
   set the uTableLineHeight of me to pValue
   updateMyAppearance
end tableLineHeight

getProp tableLineHeight
   return myLineHeight()
end tableLineHeight

function myLineHeight
   return the uTableLineHeight of me
end myLineHeight
best wishes
Skids

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Lost or slow messages resulting in partial redraw of card.

Post by Simon Knight » Sun Feb 28, 2021 11:27 am

Hi Again,

For the brave or interested here is a link to my stack file https://www.dropbox.com/s/n5ohufooaxffq ... e.zip?dl=0

Please note or be warned that this stack is intended to rename and move raw image files between folders. The renaming is to my liking and is not designed to please anyone else. This is my development version so is not fully tested but I believe that it is working as intended.

If you press the buttons to select any folders or alter the settings a small four line preferences file will be stored inside your library.

To see the issue first load the stack into the IDE and switch between the two stacks using the buttons on the bottom left of the card. Once you have demonstrated that all is well switch to the main card, edit the card script and comment out the line

Code: Select all

wait 1 milliseconds with messages
found in the opencard handler and then repeat the switching between cards.

If any of you report similar issues with a partially drawn card I will create a bug report.

For any digital camera users ....
The app is designed to aid the management of images originating on a camera memory card. It moves images from the memory card to a sub folder in the selected destination folder. These sub folders are named by SQL date e.g. 2021-02-28

The app also allows the user to add Keywords to groups of images. These groups are based on the time elapsed between shots, the idea being that I tend to take several shots of a particular subject then move on.

Any keywords added will be written to an xmp file and also be used in the new file name. I do this so that in the future I will not be caught out by the demise or price rise of a cataloging application (I thinking of you Microsoft, Apple and Adobe) (iViewMediaPro, Aperture, Lightroom). My reasoning is that I will always be able to locate my images based on capture date or keywords recorded in the filename even if the sidecars get lost.

Beta testers welcome.

Best wishes
Simon
best wishes
Skids

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Lost or slow messages resulting in partial redraw of card.

Post by AxWald » Sun Feb 28, 2021 1:23 pm

Hi,

a quick check:

"updateMyAppearance" is called very, very often. And it then loops through every single line of the field, each time. Using the relatively slow "repeat with N = 1 to to number of lines of me". Check in message watcher, this may really run quite often. So my advice would be:

A. Determine if you can call it less often.
B. Change it to a much faster "repeat for each line ..." loop, or kill the loop altogether. *)

Else, "wait 0 with messages" doesn't cost much & helps a lot.

Have fun!

*) If the field has "listBehavior", "the hilitedLines" gives a CSV of all hilited lines - so you know already what lines these are. Setting the "textColor of line N" doesn't need to be in the loop at all - it's done for each single line. The only real reason for the loop is to give alternating backColors.
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Lost or slow messages resulting in partial redraw of card.

Post by Simon Knight » Sun Feb 28, 2021 5:29 pm

Thanks for the tip. I've kept the wait line for the time being but will have a look at refactoring some of the code or even changing to a datagrid.
best wishes
Skids

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

Re: Lost or slow messages resulting in partial redraw of card.

Post by jacque » Sun Feb 28, 2021 6:33 pm

Big Sur broke your code. I had a similar problem with a card redraw that worked fine before Big Sur, and found a bug report already written. Panos' workaround for now was exactly what you did, only he just waited 0. https://quality.livecode.com/show_bug.cgi?id=23019

It might be fixed in LiveCode 9.6.2 RC-2 when several redraw problems were addressed.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”