#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;
}
It works in debug mode, but in release mode I get "Exception thrown at 0x550DC405 (sfml-system-d-2.dll) in my_$FML_stuff.exe: 0xC0000005: Access violation reading location 0x00000017."
It looks like my post is mostly code but I don't know what else to write, sorry.
It's because you are linking the debug libraries of SFML when you are running under release mode
sfml-system-d-2.dll
the -d means debug, those dll without -d is for release mode.
you can also see it here from the documentation of 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.
User contributions licensed under CC BY-SA 3.0