I am using .NET Framework 2.0 to program a 2d platformer. I am using SFML .NET as it is Cross-Platform and supported by MONO and has a mature API. My problem is that although my program compiles properly and runs properly, I get an error while closing it.
The instruction at “0x5ed0530e” referenced memory at “0x0000051c”. The memory could not be “read”
After careful debugging I have noticed that the problem occurs after I initialize the SFML String2d Class.
What is wrong; why does this error occur when closing the program? And even if nothing is wrong is there anyway to stop receiving the error so that the users of my program don’t get annoyed by it?
using System;
using SFML.Graphics;
using 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();
}
}
}
}
As you can see there is no dodgy code. Absolutely clean and simple.
Does the SFML String2d class implement IDisposable? Do you dispose all instances correctly?
It might be that the finalizer thread is disposing them when they are in an invalid state.