Unwind Radians has no check for NaN cases

I’ve noticed the FMath::UnwindRadians method does not trigger a breakpoint when it is passed NaN. Instead, it causes the editor and the game to become unresponsive. Unreal is usually pretty good about having checks in it’s functions, and I think this may be a useful one to have (especially if this bug encroaches into other functions).

:slight_smile:

Hey Lpasq-

I am not experiencing any unresponsiveness when using UnwindRadians. I tested with FMath::UnwindRadians(nan("")); which returns a NaN from the nan() function. With this line placed inside the tick function of an actor I was able to play with no issue. Let me know if you’re able to reproduce the unresponsiveness in a new project and what steps you took that caused it.

Cheers

Hey ,

Perhaps I’m a little confused as to what value is causing the crash. When I look at the value of my float in Visual Studio, I’m seeing: " -1.#IND0000 ". Here’s what I’ve done to consistently reproduce the bug:
Sorry if this is a little convoluted.

I produce the “intermediate value” (-1.#IND0000) by looking too far ahead on a spline calling the GetWorldLocationAtDistance method. Something like this:

 FVector2D intermediate_value_2d = my_spline->GetWorldLocationAtDistanceAlongSpline(a_distance_after_the_spline);

I attempt to create a heading using the atan2 method. I noted here that FMath::Atan2 handles the intermediate value with no problems, but also trips no breakpoints.

float value_that_causes_error= FMath::Atan2(center_p2.Y, center_p2.X);

I check to make sure the value is NaN, and then I call FMath::UnwindRadians

    if (FMath::IsNaN(value_that_causes_error)
        float direction of curve = FMath::UnwindRadians(value_that_causes_error);   // Stepping over this method crashes the editor

Perhaps nan(“”) produces a value with a different error code, but the value is still caught by FMath::IsNan()?

Thanks!

Hey -

I’m not sure how intermediate_value_2d relates to the other code you posted. Using your setup I included the following inside the BeginPlay() function of a custom actor class:

float ErrorValue;
ErrorValue = 0;
ErrorValue = FMath::Atan2(300, 200);

if (FMath::IsNaN(ErrorValue))
{
	float ErrorHere;
	ErrorHere = 0;
	ErrorHere = FMath::UnwindRadians(ErrorValue);
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, TEXT("Print out"));
	}
}

When I ran this I did not see the “Print out” message appear meaning the if statement wasn’t being triggered. Based on what you’ve posted it would seem that there is an issue with either the “value_that_causes_error” or the values that are used to set this variable (center_p2 X & Y).