如果我是正确的,我绝对不应该在使用 Stopwatch.GetTimeStamp 时遇到 stackoverflow 错误,尤其是在启动我的程序之后。
这是我的代码:
if (currentTicks >= lastTicks + interval)
{
lastTicks = currentTicks;
return true;
}
由 Stopwatch.GetTimeStamp() 放入的 currentTicks。这段代码在一个称为无限的方法中(我用它来控制 FPS)。有人有什么想法吗?
编辑:主表单代码:
Game game;
public Form1()
{
InitializeComponent();
game = new Game(Stopwatch.Frequency / 45);
MainLoop();
}
public void MainLoop()
{
if (game.DrawStuff(Stopwatch.GetTimestamp()))
{
Invalidate();
}
MainLoop();
}`
然后,游戏类:
public long lastTicks { get; set; }
public double interval { get; set; }
public Game(double Interval)
{
interval = Interval;
}
public bool DrawStuff(long currentTicks)
{
if (currentTicks >= lastTicks + interval)
{
lastTicks = currentTicks;
return true;
}
else
{
return false;
}
}
它在“if (currentTicks >= lastTicks + interval)”时停止。我可以看到 currentTicks 的值为 30025317628568。其他所有内容都无法评估。