errors


Unhandled exception at 0x00812767 (sfml-graphics.dll) in Heros Arena.exe: 0xC0000005: Access violation reading location 0x00000010.

is my error

1
2
3
4
5
TileLayer::TileLayer(int ts, int tw, int th, Map* map, ImageManager& im):
image( im.getImage("tiles") )
{

}


i've narrowed it down to the line image( im.getImage("tiles") )
this is the code that im.getImage() is pulling.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sf::Image& ImageManager::getImage(std::string name) {
	int loop = 0;
	bool check = false;
	for (loop=0;loop<total;loop++){
		if (names[loop]==name){
			check=true;
			break;
		}
	}
	if (check==true){
			return images[loop];
	} else {
		return images[0];
	}
}


the odd thing about this is the program runs fine but when i try to debug I get errors and cannot debug past that line.

could this have something to do with private objects being passed as references?
Last edited on
Check that names and images have a size at least as big as total.
What type is TileLayer::image, how large is total, and how large is images?
total is working properly i've narrowed it down further i think. I made everything that involves these references public instead of some privates. now it points to an error in the string class and opens the string class file . heres the entire ImageManager .cpp file. the errors still occur even when calling the function getImage directly from its variable (not a reference)
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
68
69
70
#include "StdAfx.h"
#include <iostream>
#include "ImageManager.h"
#include <fstream>

ImageManager::ImageManager(void):
total(0),
names(0),
images(0)
{
	std::string temp;
	std::ifstream file("data/imagelist.txt", std::ios::in);
    if ( file.is_open() )
    {
		while (file.good())
		{
			file >> temp;
			addImage(temp);
		}
    }
    file.close();
}


ImageManager::~ImageManager(void)
{
}
void ImageManager::addImage(std::string name)
{
	bool check = false;
	std::vector<std::string>::iterator it = names.begin();
	while( it != names.end() )
	{
		if ( (*it)==name )
		{
			check=true;
		}
		++it;
	}
	if (check==false){
		total++;
		names.push_back(name);
		name.insert(0, "graphics/");
		name.append(".bmp");
		images.push_back(sf::Image());
		images.back().LoadFromFile(name.c_str());
		images.back().SetSmooth(false);
		images.back().CreateMaskFromColor(sf::Color(255,255,255));
	}
}
sf::Image& ImageManager::getImage(std::string name) {
	int loop = 0;
	bool check = false;
	
	for (loop=0;loop<total;loop++){
		if (names[loop]==name){   ///// this line pulls an error. and if i try to cout elements of name it also pulls errors.
			check=true;
			break;
		}
	}
	
	if (check==true){
		std::cout << loop << "LOOP \n";
			return images[loop];
	} else {
		return images[0];
	}
	
	return images[0];
}



anytime i try to use the GetImage function it pulls the errors out of the string class file and points to this line in the string file

? 0 : (_Mysizt)_Ostr.width() - _Size;

the program will still execute without debugging and run perfectly fine. just when debugging does it show this. which is an annoyance because i cant debug the rest of my code.

if i run the program without debugging and add a bunch of couts that display what strings names holds it displays the names perfectly.

Last edited on
well i feel like a dumby now. But I still need help. I'm using VSC++ Express 2010. I'm trying to debug my Release build and for some reason my files always fail to open when debugging.. they always open when not debugging. I have the files placed in the same directory paths in the debug and release folders. but is there a special place you have to put them when you Debug a release build?

i just copy pasted the text files into every directory inside the project folder and that has it working now. why doesn't it just fun off the release/debug folders?
Last edited on
Topic archived. No new replies allowed.