【问题标题】:Exception thrown at 0x54FCC405 (sfml-system-d-2.dll) Access violation reading location 0x00000017在 0x54FCC405 (sfml-system-d-2.dll) 引发异常访问冲突读取位置 0x00000017
【发布时间】:2017-01-14 13:38:50
【问题描述】:
#include <SFML\Graphics.hpp>
#include <string>

using namespace sf;
using namespace std;

string calculate()
{
    static Clock clock = Clock();
    static float decimalTime = 0;

    decimalTime += clock.getElapsedTime().asSeconds();

    int decimalTimeIntPart = floorf(decimalTime);
    if (decimalTimeIntPart > decimalTime)
        decimalTimeIntPart--;
    float decimalTimeFractionalPart = decimalTime - decimalTimeIntPart;

    string binaryTimeStr;
    int n = decimalTimeIntPart;
    while (n != 0)
    {
        binaryTimeStr = to_string(n % 2) + binaryTimeStr;
        n = (n - n % 2) / 2;
    }

    binaryTimeStr += ".";
    float m = decimalTimeFractionalPart;
    int t = 4;
    while (m != 0 && t != 0)
    {
        m *= 2;
        if (m >= 1)
        {
            binaryTimeStr += "1";
            m--;
        }
        else
        {
            binaryTimeStr += "0";
        }
        t--;
    }

    clock.restart();
    return binaryTimeStr;
}

int main() 
{
    RenderWindow app(VideoMode(800, 600), "Heyyy!", !Style::Resize + Style::Close);

    Font font;
    font.loadFromFile("VT323-Regular.ttf");

    Text text("", font, 40);
    text.setColor(Color(234, 234, 234));
    text.setPosition(80, 280);

    while (app.isOpen())
    {
        Event e;
        while (app.pollEvent(e))
        {
            if (e.type == Event::Closed)
                app.close();
        }

        app.clear();

        text.setString(calculate());
        app.draw(text);

        app.display();
    }

    return 0;
}

它在调试模式下工作,但在发布模式下,我收到“my_$FML_stuff.exe 中的 0x550DC405 (sfml-system-d-2.dll) 抛出异常:0xC0000005:访问冲突读取位置 0x00000017。”

看来我的帖子主要是代码,但我不知道还能写什么,抱歉。

【问题讨论】:

标签: c++ sfml


【解决方案1】:

这是因为你在发布模式下运行时链接了SFML的调试库

sfml-system-d-2.dll 

-d 表示调试,那些没有 -d 的 dll 用于发布模式。

你也可以从 SFML 的文档中看到它

链接到与配置匹配的库很重要: “sfml-xxx-d.lib”用于调试,“sfml-xxx.lib”用于发布。糟糕的组合 可能会导致崩溃。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多