As I mentioned in
last week's nugget, I've been working a lot with the Picture Control lately. The other day, I was debugging what I *thought* was a race condition in my code for a long time. But ultimately, my code was fine...it was my lack of understanding of a little-known LabVIEW quirk that was causing the problem.
Have you ever noticed the "Synchronous Display" option on controls and indicators? You can find it by right-clicking on a control or indicator and going to the "Advanced" submenu. Well, I remember when I first learned LabVIEW almost eight years ago, I noticed the Synchronous Display option in the right-click menus, and I always wondered what it was, but I never really took the time to figure it out. Well, it turns out the LabVIEW Help has a
great description of what Synchronous Display actually means, and this help topic ultimately gave me the answer to my problem.
To summarize, all controls and indicators default to Asynchronous Display...in other words, the "Synchronous Display" option is unchecked. What this means is that, when you give LabVIEW a new value for that control or indicator (usually via its control terminal or a local variable), it will update the appearance of the front panel object with the latest value whenever it gets a chance, i.e. whenever the user interface thread gets a chance to run. In other words, some draws may never happen. If you select Synchronous Display, however, you are essentially forcing LabVIEW to update that control or indicator immediately upon its value being changed on the diagram. There's a really simple way to see the effect of this option. Create a VI with a For Loop that runs 10000 times, and wire the iteration terminal to a numeric indicator. Run the VI...it should return instantaneously. Now right-click the indicator and choose Advanced > Synchronous Display. Run the VI again. It should take a LOT longer, because you are forcing LabVIEW to update the appearance of that indicator every single time its value is changed.
So in my case, I was drawing different components of a Picture Control, with the "Erase First" option deselected...this means that new images are drawn "over" old images, and the old images remain in the Picture Control. Well, if two draws happened in quick succession (which was possible since I was keying off of Mouse Move events to do some of my drawing), sometimes, the first draw would never happen, due to the Asynchronous Display behavior. As a result, portions of my picture that needed to be there from the first draw would never appear. Now you see why I thought it was a race condition...depending on how fast my Mouse Moves occurred, I might see my first image, and I might not. My problem was fixed simply by enabling Synchronous Display on my Picture Control.
-D
P.S. - Check out past nuggets
here.
Message Edited by Darren on 11-06-2006 11:18 AM