Game Development Community

System.StackOverflowException On Set

by Viktor Rumanuk · in Torque X 2D · 12/21/2007 (10:31 am) · 2 replies

Phew, get past one problem and another hits you right in the face. Anyway, I have three public doubles set up for range, power, and speed. When I debug I get a System.StackOverflowException :
public double Range
        {
            get { return Range; }
            set (here)[b]{[/b] Range = value; }
        }
The exception helper tells me to check if I have an infinite loop or infinite recursion, which seems strange as I just want to set the value. What can I do about this?

Thanks again, Viktor

#1
12/21/2007 (11:16 am)
In the "set" method, it's assigning to Range. If it interprets that as the Range property, it will need to call the "set" method of Range. Try using slightly different names for your internal fields and your external properties (we would probably do something like _range for the internal variable).
#2
12/21/2007 (11:47 am)
Thanks, I had forgotten about this.