03-01-2010 06:44 PM - edited 03-01-2010 06:44 PM
I think I've found a bug (LV2009 SP1). In the attached VI, the top loop runs indefinitely, but the bottom loop doesn't. The problem happens on the third iteration (of the top loop), when the input to the for loop ("Row") is an empty array, but the output of the for loop tunnel ("String") keeps the value from the previous iteration. The bottom loop seems to fix the issue by explicitly indexing the 2D array, rather than using auto-indexing on the while loop input.
Jaegen
03-01-2010 09:44 PM - edited 03-01-2010 09:47 PM
please see why the second loop can be stopped. The second loop is stopped becease "for loop" is not executed and boolen array is empty. You can see "Boolen And" under which conditions can be true.
While loop auto index can not return size=0 subelement. The array index function return size=0 subelement when index > n size.
That is why the second loop can be stopped. => size=0; => for loop is not exectued;=> boolen array is empty;=> Boolen And is True. Otherwise also can not be stopped
Perhaps while loop have not function to detect the array size. The for loop may have function to detect the array size. For each iteration, it can use i to compare the array size
Second question, is why the empty string can not replace the exsting value in memory in the "for loop structure". The one only can be explained by NI developer .
Anyway, it is beter not to use while loop for array index.
03-01-2010 10:10 PM
It does seem to be a bug.
In LV 2009SP1, it does seem to be holding onto the last element rather than returning the default (empty strings) when it autoindexes past the end of the array.
I saved the VI back to LV 8.6.1 and both loops stopped after two iterations as expected.
From, LabVIEW help:
If you enable auto-indexing for an array entering a While Loop, the While Loop indexes the array the same way as a For Loop. However, the number of iterations a While Loop executes is not limited by the size of the array because the While Loop iterates until a specific condition occurs. When a While Loop indexes past the end of the input array, the default value for the array element type passes into the loop. You can prevent the default value from passing into the While Loop by using the Array Size function. The Array Size function indicates how many elements are in the array. Set up the While Loop to stop executing when the number of iterations equals the array size.
(I highlighted the most important part in bold.)
03-02-2010 03:37 AM
Hm, i cannot confirm this. Everything seems to work as stated in the help. Thanks for pointing this out, Ravens, even with highlighting of the important part 😉
I checked with LV2009f3 (eng) on Windows 7 (eng) as well as LV2009SP1 (eng) on Windows Vista (ger). Both showed the same behavior.
You can make the following change for the upper loop to terminate properly:
This works at least for my machine....
Norbert
03-02-2010 08:57 AM
Norbert,
Just to check. Did you use the VI that Jaegen posted in message #1? Run it in LV 2009 and save it back to LV 8.6 and compare the behaviors.
While I certainly wouldn't recommend using the proposed method in the top loop as a means to stop a while loop (and would more explicitly stop it like you show), when I ran the original VI in both versions, I did see different behavior. I ran it again today at work on LV2009sp1 and 8.6.1 (on XP) and again saw different behavior. (At home was same versions on Vista Home Premium 64bit)
03-02-2010 09:20 AM - edited 03-02-2010 09:21 AM
Hmmmmm, this is really odd. Sure i used the VI from Jaegen.
It works as the help states and after the second iteration, "Row" is an empty array and stays empty. If that happens, it is no surprise to me that the upper loop is running infinitly because the for loop will not execute anymore (empty array autoindexing!). So the boolen array of the four loop will not change anymore leaving the output to {False, False}. The And Array Elements will therefore result in False as well, the loop is keeping going on......
I made a little test and here is what is going on:
LV 8.6 does return an empty array of booleans for the autoindexing output tunnel of the For Loop in case that the string array at the input tunnel is empty which will result in a TRUE from the And Array Elements.
LV 2009 had major changes in the memory management. I haven't found documentation on this yet, but LV 2009 returns the last array in the autoindexing output tunnel of the For Loop if it is not updated anymore.
This is why the behavior is different between LV 8.6 and 2009.
Norbert
03-02-2010 10:03 AM
Ok, the behavior is created because of erratic behavior of the empty string array of the autoindexing input tunnel of the while loop indeed....
Filed CAR #211062.
Norbert
03-02-2010 10:45 AM - edited 03-02-2010 10:49 AM
I think you have a pretty accurate description as to what is going on. But I disagree with you on a couple points.
Basically the problem is centered around the inner For Loop. When it is receiving an empty array at its auto-indexing tunnel, it is proceeding to run using the last data it had rather than not running because it got an empty array.
This does seem to be a problem in memory management related to the combination of loops and is not expected behavior since the For Loop is supposed to run zero times when it gets an empty array.
I've attached a modified version of Jaergen's original VI. It is simplified and has a few more indicators to show that the inner For Loop is running even though it shouldn't be.
One other point, you say that if the inner for loop was not running, the boolean array would not change anymore and be leaving the output at {False, False}.
But according to LabVIEW Help
Loops produce default data on the first iteration when the shift register is not initialized.
For Loops produce default data if you wire 0 or a negative number to the count terminal of the For Loop or if you wire an empty array to the For Loop as an input with auto-indexing enabled. The loop does not execute, and any output tunnel with auto-indexing disabled contains the default value for the tunnel data type. Use shift registers to transfer values through a loop regardless of whether the loop executes."
I'd say the default data for a boolean array would be an empty array (with all the elements undefined as the default boolean of False) and not a Boolean array where exactly Two boolean elements are defined as False.
EDIT:
Thanks for filing the CAR. It looks like you got that post in there while I was trying to work through the VI trying to correlate what you were saying with what I was seeing.
03-02-2010 10:57 AM
03-02-2010 12:34 PM - edited 03-02-2010 12:35 PM
Adding a create copy between the loops will stop the inner loop