我正在使用.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();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如你所见,没有狡猾的代码.绝对干净简单.