SFML-error message and strange beeping noise

I've been learning the basics of SFML library,and i want to load a texture and make a sprite, i write the code and run it, and the window pops up(white color)
and an error message appears saying ConsoleApplication4.exe has stopped working, and most of the times there is a strange beeping noise too, and sometimes the console box has some strange symbols in it.Please help!Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
	sf::RenderWindow window, window2, window3;
	window.create(sf::VideoMode(800, 600),"My first Visual Studio window!");

	sf::Texture texture;
	if(!texture.loadFromFile("image.png",sf::IntRect(10, 10, 32, 32)))
	{
	return 1;
	}
	sf::Sprite sprite;
	sprite.setTexture(texture);
	
	while(window.isOpen())
	{
		sf::Event event;
		
		while(window.pollEvent(event))
		{
			if(event.type == sf::Event::Closed)
				window.close();			
			if(sf::Keyboard::isKeyPressed(sf::Keyboard::N))
			{
				sf::Window window2;
			window2.create(sf::VideoMode(400, 200),"Another window!");
			while(window2.isOpen())
			{
				sf::Event event;
				while(window2.pollEvent(event))
				{
					if(sf::Keyboard::isKeyPressed(sf::Keyboard::C))
						{
							window2.close();
					}
				}
			}
			}
			if(sf::Keyboard::isKeyPressed(sf::Keyboard::B))
			{
				sf::Window window3;
				window3.create(sf::VideoMode(500, 300),"The third window!");
					while(window3.isOpen())
					{
						sf::Event event;

						while(window3.pollEvent(event))
							if(sf::Keyboard::isKeyPressed(sf::Keyboard::C))
							{
								window3.close();
							}
					}
			 }
		
		}
		window.clear(sf::Color::Black);

		window.draw(sprite);
		
		window.display();

	}
return 0;
}
What happens when you comment out Lines 28 and 44? You shouldn't re-declare variables like this.
Comment out?You mean erase, right?If you mean erase i tried that and still nothing.Any other ideas?
You have not set the Sprite's position. That may help.

Output to the console and Sleep() to tell where you are in the program that the error occurs.
Last edited on
Comment out means to prep-end "//" to the beginning of a line of code so that the compiler ignores it, but the code still remains so that you don't have to type it again. My guess though is that your code is failing because your texture doesn't load. Comment out (as described above) Line 13 and tell us what happens.
Computergeek01 I tried commenting it out, I even tried erasing it, nothing changes.
Superdude how do i do that, if you could provide me with an example using my own code, that would be greatly appreciated.
Last edited on
Topic archived. No new replies allowed.