Ok, it seems it’s a Microsoft problem. I am using Visual Studio 2019 and latest compilers (Silly me!). Adding some more logging the problem is that the SpringDirectionLocal vector is not being normalized in the non-debug version of the code. Tracking that back to the PreCalculateParameters function the *SpringDirectionLocal.Normalize() *call is actually generating somewhat random vectors in the case above turning a 0,0,-40 into 0,0,-199 rather than 0,0,-1 hence the large forces generated!
Disabling global optimizations for the PreCalculateParameters function seems to fix the issue, but who knows where else this will occurr!
Apparently working version of the release build function
//Recalculate parameters to save performance
#pragma optimize( "g", off )
void UMMTSuspensionStack::PreCalculateParameters()
{
//Shift spring offsets if custom position of the stack is used
SpringOffsetTopAdjusted = SuspensionSettings.bUseCustomPosition ? SuspensionSettings.StackLocalPosition + SuspensionSettings.SpringTopOffset : SuspensionSettings.SpringTopOffset;
SpringOffsetBottomAdjusted = SuspensionSettings.bUseCustomPosition ? SuspensionSettings.StackLocalPosition + SuspensionSettings.SpringBottomOffset : SuspensionSettings.SpringBottomOffset;
//Calculate spring direction in local coordinate system
SpringDirectionLocal = SpringOffsetBottomAdjusted - SpringOffsetTopAdjusted;
SpringMaxLenght = SpringDirectionLocal.Size();
//Normalize vector and check if normalization was successful
if (!SpringDirectionLocal.Normalize())
{
SpringDirectionLocal = FVector::UpVector;
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::Printf(TEXT("%s->%s distance between Top and Bottom offsets of the spring shouldn't be zero"), *ComponentsParentName, *ComponentName));
UE_LOG(LogTemp, Warning, TEXT("%s->%s distance between Top and Bottom offsets of the spring shouldn't be zero"), *ComponentsParentName, *ComponentName);
}
//Calculate line trace points in local space, taking into account road wheel radius and tread thickness
LineTraceOffsetTopLS = SpringOffsetTopAdjusted + SpringDirectionLocal * (SuspensionSettings.RoadWheelRadius + SuspensionSettings.TrackThickness);
LineTraceOffsetBottomLS = SpringOffsetBottomAdjusted + SpringDirectionLocal * (SuspensionSettings.RoadWheelRadius + SuspensionSettings.TrackThickness);
SphereCheckShape = FCollisionShape::MakeSphere(SuspensionSettings.RoadWheelRadius + SuspensionSettings.TrackThickness);
}
#pragma optimize( "", on )
note the “#pragma optimize( “g”, off )” and “#pragma optimize( “”, on )” block
Looks like time to roll back to Visual Studio 2017!