View Full Version : array attr behaving strangely. wild behavior.

10 October 2006, 08:02 AM
Hi again everybody. You sick of me yet? Well, thanks to all of you for your patience and generosity.

I've encountered some very odd behavior. I have an array attribute whose default initial value for new elements is -1. So when I first do a getAttr on the whole attribute, I get a result like:

// Result: -1 -1 -1 -1 -1 -1 //

I then try to set all the attrs in a for loop, one at a time. I do this based on another array with the following values {4, 3, 5, 1, 2, 0 }

But I get:
// Result: 0 3 5 1 2 0 //

If I run the exact same procedure a second time, I get a correct result:
// Result: 4 3 5 1 2 0 //

The only thing different is that the values have already been set once. But why wouldn't the first element of the attr set correctly the first time, and why would it decide to set itself to 0, which is neither the initial default value nor the correct value?

Unfortunately, this screwed up value ends up causing problems in some functions in my plugin which rely on correct values. The error ends up compounding into a wild garbage value in a calculation, sufficient to cause a fatal error. Grrrrrr.

If any of you know what pecularities are causing this and if there is a resonable and elegant work around, please let me know. Thanks and cheers!

10 October 2006, 01:43 PM
show us your loop. Setting new arrayvalues should be pretty straight forward.

int $array1[5] = {-1,-1,-1,-1,-1};

int $array2[5] = {4, 3, 5, 1, 2, 0};
for ($i = 0; $i<5; $i++){
$array1[$i] = $array2[$i];

I haven't tried it out so syntaxes and declarations might be off... But as I said. Let us see the loop...

CGTalk Moderation
10 October 2006, 01:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.