SDL: Project.exe triggered a breakpoint.

Hello. Im trying to set up a simple map editor that saves the x and y positions of blocks to a .txt file, but i seem to have a problem with creation of new elements in vector, which i use as list of all blocks.
Here is the 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <fstream>
#include <iostream>
#include <string>
#include <windows.h>
#include <sstream>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

void logSDLError(std::ostream &os, const std::string &msg)
{
	os << msg << " error: " << SDL_GetError() << std::endl;
}

SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren)
{
        SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
        if (texture == nullptr)                
                logSDLError(std::cout, "LoadTexture");
        return texture;
}

void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, SDL_Rect dst, SDL_Rect *clip = nullptr){
	SDL_RenderCopy(ren, tex, clip, &dst);
}

void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, SDL_Rect *clip = nullptr)
{
	SDL_Rect dst;
	dst.x = x;
	dst.y = y;
	if (clip != nullptr){
		dst.w = clip->w;
		dst.h = clip->h;
	}
	else
		SDL_QueryTexture(tex, NULL, NULL, &dst.w, &dst.h);

	renderTexture(tex, ren, dst, clip);
}

int main(int argc, char **argv)
{
	if(SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
		logSDLError(std::cout, "SDL_Init");
		return 1;
	}

	SDL_Window *win = SDL_CreateWindow("Hitler Kirby", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
	if(win == nullptr)
	{
		logSDLError(std::cout, "CreateWindow");
		return 1;
	}

	SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if(ren == nullptr)
	{
		logSDLError(std::cout, "CreateRenderer");
		return 1;
	}
	SDL_Texture *tex = loadTexture("Spreadsheet.png", ren);
	if(tex == nullptr)
	{
		logSDLError(std::cout, "LoadTexture");
		return 1;
	}


	class playerclass
	{
	public:
		int x;
		int y;
		int xspeed, yspeed;
		int iW, iH;
		int useClip;
		SDL_Rect clips[2];
	};
	playerclass player;

	player.x = 0;
	player.y = 0;
	player.xspeed = 0;
	player.yspeed = 0;
	player.iW = 25;
	player.iH = 24;
	player.clips[0].x = 0;
	player.clips[0].y = 0;
	player.clips[0].w = player.iW;
	player.clips[0].h = player.iH;
	player.clips[1].x = 26;
	player.clips[1].y = 0;
	player.clips[1].w = player.iW;
	player.clips[1].h = player.iH;
	player.useClip = 0;

	class blockclass
	{
	public:
		int x, y;
		int iW, iH;
		int useClip;
		SDL_Rect clips[1];
	};

	std::vector<blockclass>blocklist;



	int mouseX = 0;
	int mouseY = 0;

	//Our event structure
	SDL_Event e;
	bool quit = false;
	while (!quit)
	{
		while (SDL_PollEvent(&e))
		{
			if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
			{
				SDL_GetMouseState(&mouseX, &mouseY);
				blockclass *blockToAdd = new blockclass;
				blocklist.push_back(*blockToAdd);
				blocklist.back().iH = 15;
				blocklist.back().iW = 24;
				blocklist.back().useClip = 0;
				blocklist.back().x = mouseX;
				blocklist.back().y = mouseY;
				blocklist.back().clips[0].h = blocklist.back().iH;
				blocklist.back().clips[0].w = blocklist.back().iW;
				blocklist.back().clips[0].x = 0;
				blocklist.back().clips[0].y = 36;
				blocklist.back().clips[1].h = blocklist.back().iH;
				blocklist.back().clips[1].w = blocklist.back().iW;
				blocklist.back().clips[1].x = 0;
				blocklist.back().clips[1].y = 36;
				delete blockToAdd;
				blockToAdd = NULL;
				blocklist.back()
			}
			if(e.type == SDL_KEYDOWN)
			{
				switch (e.key.keysym.sym)
				{
				case SDLK_ESCAPE:
					quit = true;
					break;
				default:
					break;
				}
			}
		}

		//Render the scene
		SDL_RenderClear(ren);
		renderTexture(tex, ren, player.x, player.y, &player.clips[player.useClip]);
		for(unsigned i = 0; i < blocklist.size(); i++)
		{
			renderTexture(tex, ren, blocklist[i].x, blocklist[i].y, &blocklist[i].clips[blocklist[i].useClip]);
		}
		SDL_RenderPresent(ren);
	}

	std::ofstream File ("data.txt");
	for (unsigned i = 0; i < blocklist.size(); i++)
	{
		File << blocklist[i].x << " ";
		File << blocklist[i].y << " ";
	}

	//DESTROY TEXTURE HERE
	SDL_DestroyTexture(tex);
	SDL_DestroyRenderer(ren);
	SDL_DestroyWindow(win);

	//Quit the program
	IMG_Quit();
	SDL_Quit();


	//Quit the program
	SDL_Quit();

	return 0;
}


Program gives me the triggered breakpoint when i try to place second block.
Nevermind it was a dumb error, i tried to assign values to clips[1] when obviously there is no clips[1] since its size is 1.
Topic archived. No new replies allowed.