Debug Assertion Failed!

ok so im lost...

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <cctype>
#include <vector>
#include <sstream>

std::vector<std::vector<sf::Vector2i>>map;
std::vector<sf::Vector2i> tempMap;

sf::Texture tileTexture;
sf::Sprite tiles;


/*...*/

void LoadMap(const char*filename)
{


	std::ifstream openfile(filename);//map

	tempMap.clear();
	map.clear();
	//reinit map usefull for map reload on key press eg:0



	if (openfile.is_open())
	{
		std::string tileLocation;
		openfile >> tileLocation;
		tileTexture.loadFromFile(tileLocation);
		tiles.setTexture(tileTexture);

		while (!openfile.eof())
		{
			std::string str, value;
			std::getline(openfile, str);
			std::stringstream stream(str);

			while (std::getline(stream, value, ' '))
			{
				if (value.length() > 0)
				{
					std::string xx = value.substr(0, value.find(','));//find ,
					std::string yy = value.substr(value.find(',') + 1);//find next ,


					int x, y, i, j;
					for (i = 0; i << xx.length(); i++)
					{
						if (isdigit(xx[i]))
							break;
					}
					for (j = 0; j << yy.length(); j++)
					{
						if (isdigit(yy[j]))
							break;
					}

					x = (i == xx.length()) ? atoi(xx.c_str()) : -1;
					y = (j == yy.length()) ? atoi(yy.c_str()) : -1;

					tempMap.push_back(sf::Vector2i(x, y));

				}

			}

			map.push_back(tempMap);
			tempMap.clear();

		}

	}

}

int main()
{

	LoadMap("map.txt");

	sf::RenderWindow Window(sf::VideoMode(800, 600), "GSRPG");

	character midget;

	sf::Texture ptexture;
	if (!midget.ptexture.loadFromFile("player.png", sf::IntRect(32, 0, 32, 32)))
		std::cout << "Error player.png";
	ptexture.setSmooth(true);

	sf::Clock clock;
	sf::Time elapsed1 = clock.getElapsedTime();
	std::cout << elapsed1.asSeconds() << std::endl;
	clock.restart();
	sf::Time elapsed2 = clock.getElapsedTime();
	std::cout << elapsed2.asSeconds() << std::endl;
	//masoara timpul inapp


	while (Window.isOpen())
	{
		sf::Event Event;
		while (Window.pollEvent(Event))
		{
			switch (Event.type)
			{
			case sf::Event::Closed:
				Window.close();
				break;
			case sf::Event::KeyPressed:
				if (Event.key.code == sf::Keyboard::Escape)
				{
					Window.close();
					break;
				}
				else if(Event.key.code == sf::Keyboard::L)
				{
					LoadMap("map.txt");
					break;
				}
	
			}
		}


		for (int i = 0; i < map.size(); i++)
		{
			for (int j = 0; j < map.size(); j++)
			{
				if (map[i][j].x != -1 && map[i][j].y != -1)
				{
					tiles.setPosition(j * 32, i * 32);
					tiles.setTextureRect(sf::IntRect(map[i][j].x = 32, map[i][j].y * 32,32,32));
					Window.draw(tiles);
				}
			}
		}

		midget.keymove();
	
		Window.draw(midget.pSprite);
		Window.display();
	}
}


no errors only warnings:
warning C4018: '<' : signed/unsigned mismatch
warning C4018: '<' : signed/unsigned mismatch
warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data


also

*insert resources loaded here*
Debug Assertion Failed!

Program: C:\Windows\system32\MSVCP120D.dll
File: e:\visualstudio\vc\include\vector
Line: 1201

Expression: vector subscript out of range

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
GSRPG.exe has triggered a breakpoint.

Debug Assertion Failed!

Program: E:\GSRPG\Debug\GSRPG.exe
File: e:\visualstudio\vc\include\vector
Line: 1202

Expression: "Standard C++ Libraries Out of Range" && 0

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
GSRPG.exe has triggered a breakpoint.

Microsoft Visual Studio C Runtime Library has detected a fatal error in GSRPG.exe.

Press Break to debug the program or Continue to terminate the program.

The thread 0x1f50 has exited with code -1073740777 (0xc0000417).
The thread 0x2160 has exited with code -1073740777 (0xc0000417).
The program '[9208] GSRPG.exe' has exited with code -1073740777 (0xc0000417).


Last edited on
1
2
3
4
5
for (int i = 0; i < map.size(); i++)
{
	for (int j = 0; j < map.size(); j++)
	{
		if (map[i][j].x != -1 && map[i][j].y != -1)
What if map[i].size() < map.size()? (or your 2D matrix is not square)
For what im using it the matrix will be allways be square
Somewhere, your 2D vector is going out of bounds. That's what the "vector subscript out of bounds" means.
I would double check the code between line 42 and line 72, as that is where you are pushing elements into both the tempMap vector and the 2D map vector. Somewhere in there, the matrix is losing its square dimensions, or you are trying to access something outside of the vector's bounds.
Last edited on
Topic archived. No new replies allowed.