Hi!
I have the following code:
FVector TestVector(
0.f,
100.f - FMath::RandRange(-10.f, 10.f),
0.f
);
UE_LOG(Log, Error, L"TestVector: %.2f, %.2f, %.2f", TestVector.X, TestVector.Y, TestVector.Z);
TestVector.Normalize();
UE_LOG(Log, Error, L"TestVector: %.2f, %.2f, %.2f", TestVector.X, TestVector.Y, TestVector.Z);
TestVector *= 10.f;
UE_LOG(Log, Error, L"TestVector: %.2f, %.2f, %.2f", TestVector.X, TestVector.Y, TestVector.Z);
In DEBUG mode this outputs the following to the log:
TestVector: 0.00, 109.68, 0.00
TestVector: 0.00, 1.00, 0.00
TestVector: 0.00, 10.00, 0.00
The last line TestVector: 0.00, 10.00, 0.00
is the expected result.
However, when I compile the exact same code in DEVELOPMENT mode the output to the log is:
TestVector: 0.00, 104.32, 0.00
TestVector: 0.00, 0.00, 0.00
TestVector: 0.00, 0.00, 0.00
The result is incorrect, the normalization failed. If I replace TestVector.Normalize(); with *TestVector = TestVector.GetSafeNormal(); *the result become correct again, both in DEBUG and DEVELOPMENT mode.
I don’t really understand why this is happening, blaming the compiler is normally a mistake but this looks indeed very strange? Especially since the methods should be marked with FORCEINLINE.
Specs: Windows 10, Visual studio 16.3.5, UE 4.22.3 no plugins.
Any ideas what might cause this? my workaround for now is to ban usage of Normalize() and stick to only using GetSafeNormal(). Any help would be appreciated!
Also posted at Answer hub for those interested in following: https://answers.unrealengine.com/que…correctly.html
EDIT: I have the same problem with UE 4.23.1