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.
You would be better off asking this question on the SFML forums. A quick Google turned up this thread which suggests that there is a problem with the String2D type.
This code will recursive infinitely:
public void Render(RenderWindow App)
{
App.Draw(this);
App.Draw(Text);
}
since App.Draw
, called on a Sprite
x
, will call x.Render(App)
. So App.Draw(this)
will internally call this.Render(App)
.
Try "EditBin.exe /NXCOMPAT:NO C:\AppName.exe" from a visual studio command line after your app is compiled.
What you'll find is that the String2d
class either:
or (more likely, given the description of your problem)
For example, is the container for the Text
property initialised at this point? Are multiple threads accessing the Text
property at the same time (I'm thinking of some sort of game-loop, in your case)?
To me, since this happens when your app is closing, I expect this SetText
method is being called during shutdown, after the form/window has been disposed by the runtime. If you put code to set this.Text
in the form's Closed
event, you'd get similar results.
User contributions licensed under CC BY-SA 3.0