0x54FCC405 (sfml-system-d-2.dll) 访问冲突读取位置 0x00000017 处抛出异常
Exception thrown at 0x54FCC405 (sfml-system-d-2.dll) Access violation reading location 0x00000017
#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;
}
它在调试模式下工作,但在发布模式下我得到 "Exception thrown at 0x550DC405 (sfml-system-d-2.dll) in my_$FML_stuff.exe: 0xC0000005: Access violation reading location 0x00000017."
看来我的 post 主要是代码,但我不知道还能写什么,抱歉。
这是因为你在 运行 发布模式
下链接了 SFML 的调试库
sfml-system-d-2.dll
-d表示debug,没有-d的dll表示release模式。
你也可以从SFML的文档中看到这里
It is important to link to the libraries that match the configuration:
"sfml-xxx-d.lib" for Debug, and "sfml-xxx.lib" for Release. A bad mix
may result in crashes.
#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;
}
它在调试模式下工作,但在发布模式下我得到 "Exception thrown at 0x550DC405 (sfml-system-d-2.dll) in my_$FML_stuff.exe: 0xC0000005: Access violation reading location 0x00000017."
看来我的 post 主要是代码,但我不知道还能写什么,抱歉。
这是因为你在 运行 发布模式
下链接了 SFML 的调试库sfml-system-d-2.dll
-d表示debug,没有-d的dll表示release模式。
你也可以从SFML的文档中看到这里
It is important to link to the libraries that match the configuration: "sfml-xxx-d.lib" for Debug, and "sfml-xxx.lib" for Release. A bad mix may result in crashes.