Jump to content

Beware of the Get Variant Attribute function


Recommended Posts

I have been unable to build a simple example of this bug so I have not reported it to NI yet, but I figured this was annoying enough to warn people about. Not sure if all the steps are needed to repro this, but I included them all anyways.

I have discovered in some complex code in my application that the 'Get Variant Attribute' function can sometimes behave abnormally. Here is what I am seeing:

I start with an empty variant (Top Variant).

I call 'Get Variant Attribute' to get a specific attribute (Parent Attribute 1) (if it does not exist, I should get an empty default variant).

I then add a sub attribute (Child Attribute 1) to the 'found' (or empty if not found) Parent attribute.

I then replace the Parent attribute in the Top Variant with this new variant (with the sub attribute attached). This is basically a tree structure.

So far, I have this:

-Top Variant

--Parent Attribute 1

----Child Attribute 1

I continue this until my Parent has several children:

-Top Variant

--Parent Attribute 1

----Child Attribute 1

----Child Attribute 2

----Child Attribute 3

----Child Attribute 4

----Child Attribute 5

I then remove these one by one by getting the Parent variant, calling 'Delete Variant Attribute' with a child as the attribute to remove and then replacing the Parent into the Top Variant. I leave child 3, however. Now I have this:

-Top Variant

--Parent Attribute 1

----Child Attribute 3

Now, I replace the Parent with an empty variant to 'Flush' the tree. Now I have this:

-Top Variant

--Parent Attribute 1

Here is where the bug comes in. Now I repeat the whole process, but for Parent Attribute 2. When I call Get Variant Attribute on the Top Variant and give it the name 'Parent Attribute 2', it should give me a default empty variant because that attribute does not exist in the Top Variant. Instead this is what I get:

-Top Variant

--Parent Attribute 1

--Parent Attribute 2

----Child Attribute 1

----Child Attribute 2

----Child Attribute 3

----Child Attribute 4

----Child Attribute 5

WTF? :throwpc: The new attribute seems to inherit all the child attributes that ever existed in the new Parent's sibling (which still exists, but is empty)

The fix is easy, however. Just wire an empty variant to the default value terminal of the 'Get Variant Attribute' function when you try to get an attribute and the problem goes away.

Just don't trust that the unwired default will really be an empty variant.

Now, as I said, I cannot seem to reproduce this with an example VI, but I can instrument my code and see this happening. I dump the whole Top Variant tree to a file before the call to 'Get Variant Attribute' and then right after. I also confirmed that the 'Found' output is false and the value output contains the 5 child attributes, even though nothing is wired to the 'default value' input.

Link to comment

I think this is the same bug I found in 8.2. It already has a CAR assigned but I have no idea if it was fixed.

EDIT: Oops, should have checked before posting... it was reportedly fixed in 8.5. Might be a related problem, though.

Edited by ned
Link to comment

Looks like they might have simply moved the bug instead of fixing it. As I said, I cannot reproduce it in a simple VI under the 8.6.1 dev environment, but I can reproduce it in my exe running under the 8.6.1 RTE. Not sure if the issue is in the RTE, or the fact that the code is inside a large massively parallel application where just about everything is a reentrant shared clone.

Link to comment

Yes, I can confirm that appears to demonstrate the bug. My first CAR of 2010! And it applies to a LV version I have not even ported to yet!

Any idea when this CAR will be fixed and released? LV2010?

BTW: I thought the new version of LV was 2009, not 9.0!

post-2411-126988470845_thumb.png

I've noticed the about says both 9.0 and 2009, and the Windows registry also has it as 9.0.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.