Problems with Matrix4.IDENTITY

Molt

01-04-2011 13:09:15

There seems to be a problem with the implementation of Matrix4.IDENTITY, it's returning a reference to a single shared Matrix4 rather than a new Matrix4 each time, which allows client code to effectively change the value of the underlying constant.

The code below demonstrates what I mean here, and also includes a test with Vector3.ZERO as that doesn't seem to have this problem.

var m = Mogre.Matrix4.IDENTITY;
Console.WriteLine("M: {0}, Matrix4.IDENTITY: {1}", m.GetTrans(), Mogre.Matrix4.IDENTITY.GetTrans());
m.SetTrans(new Mogre.Vector3(10, 10, 10));
Console.WriteLine("M: {0}, Matrix4.IDENTITY: {1}", m.GetTrans(), Mogre.Matrix4.IDENTITY.GetTrans());

var v = Mogre.Vector3.ZERO;
Console.WriteLine("V: {0}, Vector3.ZERO: {1}", v, Mogre.Vector3.ZERO);
v.x = 23;
Console.WriteLine("V: {0}, Vector3.ZERO: {1}", v, Mogre.Vector3.ZERO);


...the output of running this is....
M: Vector3(0,0,0), Matrix4.IDENTITY: Vector3(0,0,0)
M: Vector3(10,10,10), Matrix4.IDENTITY: Vector3(10,10,10)
V: Vector3(0,0,0), Vector3.ZERO: Vector3(0,0,0)
V: Vector3(23,0,0), Vector3.ZERO: Vector3(0,0,0)


Apologies for presenting a bug rather than a patch- I'm currently running a prebuilt binary as I've not yet had time to try and build my own and so couldn't test any patch.