chances / slimmath

Automatically exported from code.google.com/p/slimmath
0 stars 0 forks source link

Matrix.Multiply(ref Matrix, ref Matrix, out Matrix) overlap #16

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
During all operation of multiplication i've noticed that i'm getting some 
overlapping result if i
send the same matrix as ref and out, XNA does not overlapping, probably before 
assign of result you should
assing temp float values and after that store them to final result;

Ex:
Matrix left = Matrix.Identity;
Matrix right = Matrix.Scaling(1.0f,1.0f,1.0f);
Matrix.Multiple(ref left, ref right, out right);

In this case right is overlapped.
This happens with all ref passed parameters.

Thanks

Original issue reported on code.google.com by amerkol...@gmail.com on 21 Jun 2011 at 12:54

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. I was really hoping that this problem didn't exist. 
Pretty much every method will have to be checked for this now.

I should really work on getting a better unit testing framework made. Using 
things like Fluent Assertions and a better approach.

If you have fixed this yourself or you want to contribute anything in any way 
just post any of your work here. It would be a great help since work on this 
project is rather sporadic.

To be more clear in case someone cares to resolve all of these issues. The 
problem is that during the mathematical operations in a lot of pointer based 
methods (ref and out) the results of said mathematical operations are stored 
directly in the out parameter. If the ref parameter and the out parameter are 
pointing to the same object and the mathematical operations are using that ref 
parameter and directly outputting to the out parameter, than the next 
mathematical operation may be using the outputted value instead of the original 
ref parameter. Two ways this can be solved. 1) Store the original values that 
would otherwise be overridden during the mathematical operations in temp 
variables. Using this approach, only the values that will (or could) be 
overridden should be stored in temp variables. Do not store all values in temp 
variables if not necessary. 2) Create a new object for the out parameter. Store 
all results from the mathematical operations in this new object and at the end 
of the method assign the out parameter to this newly created object. I do not 
prefer this method unless every value will be overridden during the 
mathematical operation. Use option 1 if at all possible.

Original comment by Jorgy...@gmail.com on 27 Jul 2011 at 3:25