當我填充橢圓不僅僅是一個橢圓,而是多個橢圓時,我得到一個stackoverflow異常。StackOverflow在GraphicsCreator()的異常。FillEllipse
我不認爲這是圖形創建者的問題。但我想不通爲什麼調試器在FillEllipse
命令
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中
單個對象
你嘗試逐步執行代碼,看看發生了什麼? – djs
我無法逐步完成700次代碼 –
我想你可以在那之前發現問題。 – djs