Can't find the source of .NET error, need Help

-6

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.

c#
.net
2d
sfml
asked on Stack Overflow Jun 28, 2011 by ApprenticeHacker • edited Jun 29, 2011 by Sampson

5 Answers

8

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.

answered on Stack Overflow Jun 28, 2011 by Alex Peck
3

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.

answered on Stack Overflow Jun 28, 2011 by Mark Rendle
3

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).

answered on Stack Overflow Jun 28, 2011 by Konrad Rudolph
1

Try "EditBin.exe /NXCOMPAT:NO C:\AppName.exe" from a visual studio command line after your app is compiled.

answered on Stack Overflow Jun 28, 2011 by Eric Dahlvang
1

What you'll find is that the String2d class either:

  • Has a bug

or (more likely, given the description of your problem)

  • Is being called at the wrong point in the app's lifecycle.

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.

answered on Stack Overflow Jun 28, 2011 by Neil Barnwell • edited Jun 28, 2011 by Neil Barnwell

User contributions licensed under CC BY-SA 3.0