xBimTeam / XbimGeometry

XbimGeometry contains the CLR interop libraries and the c++ engine used to compute the 3D geometry of models.
https://xbimteam.github.io/
Other
260 stars 131 forks source link

Uninitialized matrix is supposed to be Identity, but this may not be true in case of accessing some properties #395

Closed Phezis closed 2 years ago

Phezis commented 2 years ago

Hello.

I've encountered a problem with an uninitialized matrix. In case of uninitialized matrix, properties are being filled with the parameters of the identity matrix during first accessing of some properties (for example M11). But some other properties, for example Up, Down, etc., use the fields _m** directly. Uninitialized matrices are supposed to be identity, but accessing of Up, Down, etc. before accessing some other properties results in a zero vector.

Code to reproduce the issue:

var matrix = new XbimMatrix3D();                // Instance of a matrix whose _isNotDefaultInitialised is filled with false
// Debug.Assert(!matrix.Up.Length.IsZero());    // Fails but shouldn't
var _ = matrix.M11;                             // Forces filling by values of Identity matrix
Debug.Assert(!matrix.Up.Length.IsZero());       // Passes