Unhandled exception; Access violation reading location.

the program runs like is should, but when you close it this pops up - Unhandled exception at 0x772115de in Pong 2.exe: 0xC0000005: Access violation reading location 0xfeeefef6.

I think it has to do with these global objects? I'm using SFML 2.

Tower.h

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
class Tower
{
public:
	sf::RectangleShape TowerSpr;

	sf::Vector2i TowerVector;

	
	
	
	Tower();

	~Tower();
};



extern std::vector<Tower> Towers;
extern bool clicked;
extern int towerCount;
extern sf::Vector2f CurrentBoxSizeVector;

extern sf::Text BoxCount;
extern sf::Text BoxColor;
extern sf::Text BoxSizeX;
extern sf::Text BoxSizeY;
extern sf::Text ChangeSize;
extern sf::Text PreviewBoxSizeXChange;
extern sf::Text PreviewBoxSizeYChange;


void TowerPushback(sf::RenderWindow& Window);
void TowerDraw(sf::RenderWindow& Window);
void UI(sf::RenderWindow& Window);
void SetSize(sf::RenderWindow& Window);
void SetColor(sf::RenderWindow& Window);


static inline std::string int2Str(int x);


I'll post more if you need more. There's only 3 files to the project.

Thanks a bunch :)!
Last edited on
Can ~Tower() run safely after main has ended? Best is probably to avoid having global variables.
What do you mean run safely after main has ended?

I've heard that I shoudn't, but I don't know why/how I'd do it another way.
Bump please. I don't know how i'd dothis with global variables.
Do not use global SFML objects. It will definitely cause you problems. From what I can see there, it is most likely the sf::Text variables that are the problem.
Last edited on
Maybe if you do post code...
In the meanwhile, show a backtrace.
Thanks, Cire. how would I fix it then?

Show code for what...? If you ask what part I'll give you it. What's a backtrace?

Code for a minimal setup that does reproduce your problem.

backtrace http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_42.html
$ gdb a.out
> run
(caput)
> backtrace
Thanks, Cire. how would I fix it then?

Don't make 'em globals.
Topic archived. No new replies allowed.