找不到 .NET 错误的来源,需要帮助

发布于 2024-11-17 16:49:45 字数 1503 浏览 5 评论 0原文

我正在使用 .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();
            }
        }
    }
}

正如您所看到的,没有任何狡猾的代码。绝对干净简单。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

泪之魂 2024-11-24 16:49:45

SFML String2d 类是否实现 IDisposable?您是否正确处理了所有实例?

当它们处于无效状态时,终结器线程可能正在处理它们。

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.

北方的巷 2024-11-24 16:49:45

您最好在 SFML 论坛上提出这个问题。谷歌很快就发现了这个帖子,这表明有一个String2D 类型的问题。

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.

等风来 2024-11-24 16:49:45

此代码将无限递归:

    public void Render(RenderWindow App)
    {
        App.Draw(this);
        App.Draw(Text);
    }

因为在 Sprite x 上调用 App.Draw 时,将调用 x.Render(App)< /代码>。因此,App.Draw(this) 将在内部调用 this.Render(App)

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

若沐 2024-11-24 16:49:45

编译应用程序后,从 Visual Studio 命令行尝试“EditBin.exe /NXCOMPAT:NO C:\AppName.exe”。

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

往事随风而去 2024-11-24 16:49:45

您会发现 String2d 类要么:

  • 有错误

,要么(更有可能的是,考虑到问题的描述)

  • 在应用程序生命周期的错误点被调用。

例如,此时 Text 属性的容器是否已初始化?多个线程是否同时访问 Text 属性(在您的情况下,我正在考虑某种游戏循环)?

对我来说,由于这种情况发生在您的应用程序关闭时,我希望在关闭期间(在运行时处置表单/窗口之后)调用此 SetText 方法。如果您在表单的 Closed 事件中添加代码来设置 this.Text,您会得到类似的结果。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文