当我填充椭圆时,我得到一个stackoverflow异常,而不仅仅是一个椭圆,而是许多椭圆。
我不认为这是图形创建者的问题。但我无法弄清楚为什么调试器在FillEllipse
命令中指向 stackoverflow 异常
public void createPath(Stance currentStance)
{
if(toSort.Count > 0)
{
toSort.Remove(currentStance);
counter++;
}
this.currentForm.FillEllipse(new SolidBrush(Color.Red),new Rectangle(currentStance.location.X-3, currentStance.location.Y - 3, 6 , 6));
foreach(Stance subStance in currentStance.childStances)
{
double weight = level(currentStance, subStance, 1)+ currentStance.StanceWeight;
if (subStance.StanceWeight == -99999999999999)
{
currentStance.dajkstrasChildren.Add(subStance);
subStance.parentStance = currentStance;
subStance.StanceWeight = weight;
toSort.Add(subStance);
}
else
{
if(weight > subStance.StanceWeight)
{
try
{
subStance.parentStance.dajkstrasChildren.Remove(subStance);
}
catch (NullReferenceException e)
{
Console.WriteLine("null reference");
}
subStance.parentStance = currentStance;
currentStance.dajkstrasChildren.Add(subStance);
subStance.StanceWeight = weight;
}
}
}
foreach(Stance subStance in currentStance.secondChildStances)
{
double weight = level(currentStance, subStance, 1) + currentStance.StanceWeight;
if (subStance.StanceWeight == -99999999999999)
{
currentStance.dajkstrasChildren.Add(subStance);
subStance.parentStance = currentStance;
toSort.Add(subStance);
subStance.StanceWeight = weight;
}
else
{
if (weight > subStance.StanceWeight)
{
if(subStance.parentStance != null)
{
try
{
subStance.parentStance.dajkstrasChildren.Remove(subStance);
subStance.parentStance = currentStance;
currentStance.dajkstrasChildren.Add(subStance);
}
catch(NullReferenceException e)
{
Console.WriteLine("null reference");
}
}
}
}
}
toSort.Sort(new Stance());
if(toSort.Count != 0)
{
createPath((Stance)toSort[0]);
}
}
它是一种递归方法,但它不能递归到无穷大,因为它总是从 toSort ArrayList 中弹出一个对象