Download

Came across and c++ bug/error and I want to know why it is happening.

Basically I have a structure where I have used operator overloading for its initialization



	FSplinePathProperty(float _AccelerationKmpH, float _DeAccelerationKmpH, float _MaxSpeedLimitKmpH, float _TractionChangePerSecond)
	{
		AccelerationKmpH = _AccelerationKmpH;
		DeAccelerationKmpH = _DeAccelerationKmpH;
		MaxSpeedLimitKmpH = _MaxSpeedLimitKmpH;
		TractionChangePerSecond = _TractionChangePerSecond;
		ConvertToCmpS();
	}

When I use it in a function like this.


FSplinePathProperty ASplinePathConstructor::GetSplinePathProperty(FSplineClosestLocation SplineClosestLocation, USplineComponent* SplineComponent)
{
        ...
        ...
	FSplinePathProperty SplinePathProperty(StoredSplineCheckPoints[SplineClosestLocation.StartSegment]->CenterSplineProperties*SegmentStartCoeff
		+ StoredSplineCheckPoints[SplineClosestLocation.EndSegment]->CenterSplineProperties*SegmentEndCoeff);

	return SplinePathProperty;
}

The values in the structure get kind of bugged.
The variable values inside the structure gets swapped and bugged up. If I use structures 1 variable, its giving the value of another variable.

Instead if I add just a simple AddOnScreenMessage in between, it gets solved.
So this works and seems to be solving the problem


FSplinePathProperty ASplinePathConstructor::GetSplinePathProperty(FSplineClosestLocation SplineClosestLocation, USplineComponent* SplineComponent)
{
        ...
        ...
	FSplinePathProperty SplinePathProperty(StoredSplineCheckPoints[SplineClosestLocation.StartSegment]->CenterSplineProperties*SegmentStartCoeff
		+ StoredSplineCheckPoints[SplineClosestLocation.EndSegment]->CenterSplineProperties*SegmentEndCoeff);

	GEngine->AddOnScreenDebugMessage(-1, GetWorld()->DeltaTimeSeconds, FColor::Red, "666 Hail Satan!"); // LoL
	return SplinePathProperty;
}

On the other hand this also seems to give the correct result


FSplinePathProperty ASplinePathConstructor::GetSplinePathProperty(FSplineClosestLocation SplineClosestLocation, USplineComponent* SplineComponent)
{
        ...
        ...
	FSplinePathProperty SplinePathProperty = FSplinePathProperty(StoredSplineCheckPoints[SplineClosestLocation.StartSegment]->CenterSplineProperties*SegmentStartCoeff
			+ StoredSplineCheckPoints[SplineClosestLocation.EndSegment]->CenterSplineProperties*SegmentEndCoeff);

	return SplinePathProperty;
}

I want to know why is this happening in the first place and how is a DebugMessage solving it?

Edit…

Typed Came across “and” instead of “this”.
Its like 5:30 am here lol