我正在使用 .NET Framework 2.0 来编写 2d 平台游戏。我正在使用 SFML .NET,因为它是跨平台的,受 MONO 支持,并且具有成熟的 API。我的问题是,虽然我的程序可以正确编译并正常运行,但在关闭它时出现错误。
“0x5ed0530e”处的指令引用了“0x0000051c”处的内存。无法“读取”内存
经过仔细调试,我注意到在我初始化 SFML String2d 类之后出现了问题。
怎么了; 为什么关闭程序时会出现这个错误?即使没有任何问题,是否仍然可以停止接收错误,以便我的程序的用户不会对此感到恼火?
使用系统;使用 SFML.Graphics;使用 SFML.Window;
namespace ProGUI
{
class TextBox : Sprite
{
private String2D Text;
public TextBox(RenderWindow App)
{
Image = new Image(App.Width, App.Height / 4, new Color(0, 0, 0));
Position = new Vector2(0, App.Height - App.Height / 4);
}
public void SetText(string text)
{
Text = new String2D(text);
Text.Font = new Font("Greyscale_Basic_Bold.ttf");
Text.Position = new Vector2(Position.X + 5, Position.Y + 5);
Text.Size = 12;
}
public string GetText()
{
return Text.Text;
}
public void Render(RenderWindow App)
{
App.Draw(this);
App.Draw(Text);
}
public void MainLoop(RenderWindow App, Color clr)
{
while (App.IsOpened())
{
App.Clear(clr);
App.DispatchEvents();
App.Draw(this);
App.Draw(Text);
App.Display();
}
}
}
}
如您所见,没有不可靠的代码。绝对干净和简单。