Cant assign values to UT_Matrix3D . HDK

   675   2   2
User Avatar
Member
40 posts
Joined: Oct. 2012
Offline

UT_Matrix3D res;
fpreal m00,m01,m02,m10,m11,m12,m20,m21,m22 = 0;
res.zero();
int size = myGDP->getPointMap().indexSize();
for(GA_Size i=0; i < size ; i++)
{
GA_Offset ptoff = myGDP->pointOffset(i);
UT_Vector3D pos = myPos.get(ptoff);
UT_Vector3D r = pos - mycog;
m00 += (r*r) + (r*r); m01 += -r*r; m02 += -r*r;
m10 += -r*r; m11 += r*r + r*r; m12 += -r*r;
m20 += -r*r; m21 += -r*r; m22 += r*r + r*r;

}

res = MASS(now) * UT_Matrix3D(m00,m01,m02,m10,m11,m12,m20,m21,m22);

for (int i = 0; i < 3 ; i++)
{
cout << “ old:” ;
fpreal val = 0;
for (int j = 0; j < 3; j++)
{
cout << “ ” << res;
if (fabsf((float)res) < 0.01)
{
res = val;
cout << “new: ” << res << endl;
}
}
cout << endl;
}

return res;

I have this code but it seems I cannot assign values to specific locations with the UT_Matrix3D . I have attached the console output.
Am I doing it wrong? is there a correct way to assign specific values.

Attachments:
MatrixError.JPG (37.4 KB)

User Avatar
Member
1743 posts
Joined: March 2012
Offline
Yikes! Thanks for catching this! :shock:

There are a few scary things here. UT_Matrix3T<T>:perator is a const function and returns UT_Vector3T<T>, by *value*. UT_Vector3T<T>:perator correctly returns T&, but it's too late, because the UT_Vector3T<T> is a temporary on the stack, not the original in UT_Matrix3T<T>. It's also scary that the compiler doesn't warn that you're assigning to a temporary. It's additionally scary, because UT_Matrix4T and UT_Matrix2T have the same issue.

This is the kind of thing that makes me wonder just how much code has this bug in it. I've already found two places, (thankfully both places that seem unlikely to be hit). It's been like this since at least 1998.

For now, res(i,j) or even res(i) should work correctly. I'll see if I can fix res. It shouldn't break binary compatibility, since it's marked inline, so I'll see if I can backport it to 15.0… after I've fixed the bugs.
Neil Dickson - Writing code for fun and profit since… 2005? Wow, I'm getting old.
https://www.youtube.com/user/NeilGDickson/videos [www.youtube.com]
User Avatar
Member
1743 posts
Joined: March 2012
Offline
Tomorrow's build of Houdini 15.0 should have this fixed. Thanks again for catching this!
Neil Dickson - Writing code for fun and profit since… 2005? Wow, I'm getting old.
https://www.youtube.com/user/NeilGDickson/videos [www.youtube.com]
  • Quick Links