(SFML library) RenderWindow constructor throws exception - c++

I am getting started with SFML with Visual Studio 2019. I followed this tuttorial and launched the app successfuly. But without any changes to the code I launched it one more time and it gives me this error:
Exception thrown at 0x53582687 (sfml-system-2.dll) in Voidger.exe: 0xC0000005: Access violation reading location 0x0000016E. occurred
on this line:
RenderWindow window(VideoMode(200, 200), "SFML works!"); //not really
Ever since the app will output the same error and will occasionaly create a window if some magic stars allign. When I discovered the error I tried to create a new project but had issue with linker so abanded it as the other app didn't even start.
Here is the full code (provided on official website):
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace sf;
int main()
{
std::cout << "H\n";
RenderWindow window(VideoMode(200, 200), "SFML works!"); // error line
CircleShape shape(100.f);
shape.setFillColor(Color::Green);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
The funniest thing is that the code always launches, outputs the h in cmd and most of times exits with code -1073741819.
Edit:
Here is config manager settings that I use.

Related

c++ sfml writes to the console: Failed to load image "". Reason: Unable to open file

I tried to upload the image via sfml probably in all possible ways, but I got an error in the console
My code:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Texture texture;
int i=0;
if (!texture.loadFromFile("box.jpg"))
{
std::cout << "Error!";
window.close();
return 1;
}
sf::Sprite sprite;
sprite.setTexture(texture);
sf::Event event=sf::Event();
while (window.isOpen())
{
if (event.type == sf::Event::Closed)
window.close();
window.draw(sprite);
window.clear();
window.display();
}
return 0;
}
Maybe I'm doing something wrong, I'm a beginner c++ and sfml developer.
My settings:
https://i.stack.imgur.com/OF9FA.png
https://i.stack.imgur.com/u2ZSC.png
The file with the picture is in all folders starting from the repos
I dragged the file over all folders in the solution folder, starting from the very first folder ending with the x64 folder, all without success, I searched the question on the Internet, I did not find. \
I tried to move the image to the C folder and specified the path to the image C:\\box.jpg, I got an error in the console:Failed to load image "╨°│╕;☻C:\box.jpg
‼b√⌂Г0b√⌂9Ц ☻ў⌂ ♥X☻ ў⌂Я0b√⌂И·/WJИ·/WJ¶·/WJж╬▀pp↓ut ☻ў⌂)w ☻ў⌂☺p↓│▼√⌂╜О ☻ў⌂☺P?Ь╡;☻└ЙЪ╡;☻`t ☻ў⌂╬u ☻ў⌂Ё ☻ў⌂ Є ☻ў⌂аK♥ў⌂ИK♥ў⌂Оt ☻ў⌂╛w ☻ў⌂¶v╞р√⌂#¶WJб&╢с√⌂0√  ш♦0√  ╨♦↓
You can start from here.
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Texture texture;
int i = 0;
if (!texture.loadFromFile("box.jpg")) // check file path or you can execute the program from command line to make sure
{
std::cout << "Error!";
window.close();
return 1;
}
sf::Sprite sprite;
sprite.setTexture(texture);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event)) // poll event
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(); // clear first
window.draw(sprite);
window.display();
}
return 0;
}
If you don't use the absolute file path the folder tree is as follows:
C:\...\SFML
├───SFML // the image file needs to be here to run from IDE
│ └───x64
│ └───Debug
│
└───x64
└───Debug // the image file needs to be here to run from command line
└───Release // the image file needs to be here to run from command line
Who has the same problem go to the project -> properties -> configuration properties -> advanced -> use debugging libraries, by default it is yes, you need to set it to default or "no".
Translated through a translator, the translation may not be accurate
(Sorry for my English)
Make sure the image you want to load is in the same folder as the c++ project file. it doesn't need to be anywhere else but there.
Also make sure your file is named as it is in your program (box.jpg).
You should also move window.clear(); to above window.draw(sprite); or the image wont be displayed.

error for "Texture" sf not loading for cpp framework called sfml

I am trying to load my texture onto my window.... however when I compile in visual studio on windows 10 laptop It says "sf has no member texture" I'm honestly not sure what on earth is going on! for whatever reason its not loading the sf! if you have any ideas please let me know... thanks so much it means a great deal to me! (I have also tried to use "#include" and it has not worked out for me unfortunately)
#include <SFML/Window.hpp>
int main()
{
sf::Texture texture;
if (!texture.loadFromFile("sheet_1.png"))
{
// error...
}
sf::Window window(sf::VideoMode(800, 600), "My window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
Since sf::Texture is not included in Window.hpp you need to also include Graphics.hpp in your project.
#include <SFML/Graphics.hpp>

Error when tring to use tgui c++

I have been building a game using SFML in c++ on windows. I have now finished the game and I have been trying to create a GUI using TGUI because it looked simple and easy to use. I have set it up in my VC++ project and compiled a seemingly simple piece of code.
#include <SFML/Window.hpp>
#include <TGUI/TGUI.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
tgui::Gui gui(window);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
gui.handleEvent(event);
}
window.clear();
gui.draw();
window.display();
}
return 0;
}
The code compiles fine, however immediately when I start the code I get an
Unhandled exception at 0x80002610 in Test.exe: 0xC0000005: Access violation executing location 0x80002610.
I was wondering where the access violation could possibly be coming from. Thanks for your help.

SFML error loadFromFile()

I have the following code:
#include <SFML\Graphics.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Render");
sf::Image image;
sf::Texture texture;
sf::Sprite sprite;
image.loadFromFile("D:/Project/Sprites/bt1.png");
texture.loadFromImage(image);
sprite.setTexture(texture);
sprite.setPosition(100.0f, 100.0f);
sf::Event event;
while (window.isOpen())
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
It's very simple, but it didn't work.
I tried using different kinds of paths:
D:/Project/CPP/Game_Engine/Debug/sprites/first.bmp
D:\\Project\\CPP\\Game_Engine\\Debug\\sprites\\first.bmp
d:\\Project\\CPP\\Game_Engine\\Debug\\sprites\\first.bmp
Then I tried using different files:
D:/Project/Sprites/bt.png
D:/Project/Sprites/anim.bmp
D:/Project/Sprites/boy.jpg
Compiler indicates at the following line:
image.loadFromFile("D:/Project/Sprites/bt1.png");
More precisely, Program crashes on this line.
My configuration is the following:
Error/crash message is the following:
Необработанное исключение по адресу 0x5007DEF8 (msvcr110.dll) в
SFML_ERROR.exe: 0xC0000005: нарушение прав доступа при чтении по
адресу 0x03BC1000.
Translation is the following:
Unhandled exception at 0x5007DEF8 (msvcr110.dll) in
SFML_ERROR.exe: 0xC0000005: Access violation reading on
Address 0x03BC1000.
My problem is mixed Debug/Release, I used sfml-window.lib, but I have to use `sfml-window-d.lib'. I can't use the debug SFML library because I am using VC++ 2013 (v120, but SFML requires v110). So, I recompiled the official library and it worked!

SFML won't open a window?

So, as the title suggests, I am trying to create a simple Window using SFML 1.6 in CodeBlocks (MinGW v.4.7.0) on Windows 7 (no, I'm not using an ATI GPU).
This is the code:
#include <SFML/Window.hpp>
int main()
{
sf::Window App(sf::VideoMode(800, 600, 16), "SFML Window");
App.Display();
return 0;
}
Whenever I try to run this code, it just says Program.exe is not responding and has to be shutdown using Close this program. The funny thing is, the first tutorial offered on the SFML tutorial website (the one utilizing sf::Clock in a console) works, so the libraries are loaded properly.
Can someone help me find the cause of the error I'm getting?
Other than the crash, I get no compiler or application errors.
The problem is that you haven't created the main loop which polls for events and handles OS messages. Append this to main() (yes, this is a snippet from the SFML documentation):
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Clear the screen
App.Clear();
// Put your update and rendering code here...
// Update the window
App.Display();
}
It is therefore not necessary for you to call App.Display() after you create the window.
For those who want the whole thing, this is a snippet extracted from the SFML website.
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "SFML Window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
You will get: