This is my first time working with tuples, and I created a tuple propery.
public (float minX, float maxX, float minY, float maxY) BoundsTuple
{
private get => BoundsTuple;
set
{
BoundsTuple = value;
}
}
// BoundsTuple = value; causes stackoverflow error
This is my Unity console error:
StackOverflowException: The requested operation caused a stack overflow. Clump.set_BoundsTuple (System.ValueTuple`4[T1,T2,T3,T4] value) (at Assets/Scripts/EverythingClouds/Clump.cs:17)
How can I fix this?
Not to get a stackoverflow while setting the tuple property
CodePudding user response:
Milan's answer: You’re setting the value of your property, a cyclic operation. Try public (float minX, float maxX, float minY, float maxY) BoundsTuple { get; set; } instead.
CodePudding user response:
This is not about a tuple this is about properties in general.
Both the get
ter and set
ter or your property BoundsTuple
refer to the very same BoundsTuple
property again.
You will either convert this to an auto-property
public (float minX, float maxX, float minY, float maxY) BoundsTuple { get; set; }
or introduce a backing field
privte (float minX, float maxX, float minY, float maxY) _boundsTuple;
public (float minX, float maxX, float minY, float maxY) BoundsTuple
{
get => _boundsTuple;
set => _boundsTuple= value;
}