Problem with my code C++ using Allegro 5 - R6010 Abort() has been called

Firstly Hi, I'm Ryan I just joined, this forum has helped me quite abit although this is my first post.

I'm creating a game in c++ using Allegro 5, my deadline is approaching and I'm having problem after problem, complete newbie here.

Here's my latest problem that I cannot seem to find a solution for.

I'm getting a Debug error "R6010 - Abort() has been called"

In the debug window i get
"Assertion failed: rx >= 0, file allegro-git\addons\primitives\high_primitives.c, line 944

If you look at the code below everything was working fine, the only change I have made is a new object which is FASTCAR fastcarr. I basically went off the TRAFFIC object as that worked fine.

I have tried various changes, for example with and without '&' before 'fastcarr', changing the ID etc.

I hope somebody can help :)

This is the main file

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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_native_dialog.h>		
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include "objects.h"



ALLEGRO_DISPLAY *display = NULL;

void InitCar(CAR &Player);
void DrawCar(CAR &Player);
void MoveUp(CAR &Player);
void MoveDown(CAR &Player);
void MoveLeft(CAR &Player);
void MoveRight(CAR &Player);

void InitTRAFFIC(TRAFFIC Enemys[], int size);
void DrawTRAFFIC(TRAFFIC Enemys[], int size);
void StartTRAFFIC(TRAFFIC Enemys[], int size);
void UpdateTRAFFIC(TRAFFIC Enemys[], int size);
void CollideTRAFFIC(TRAFFIC Enemys[], int Tsize, CAR &Player);

void InitFASTCAR(FASTCAR &fastcarr);
void DrawFASTCAR(FASTCAR &fastcarr);
void StartFASTCAR(FASTCAR &fastcarr);
void UpdateFASTCAR(FASTCAR &fastcarr);

//Globals
const int width = 800;
const int height = 400;
const int NUM_ENEMY = 10;
enum KEYS{ UP, DOWN, LEFT, RIGHT};
bool keys[4] = {false, false, false, false};


int main(void)
{

	//object variables
	CAR Player;
	TRAFFIC Enemys[NUM_ENEMY];
	FASTCAR fastcarr;
	
	//variables
	const int fps = 60;
	bool redraw = true;
	bool done = false;
	int counter =0;
	int counter2;
	
	
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_FONT *font18 = NULL;

	if(!al_init())
		return -1;									//initialize allegro

	display = al_create_display(width, height);		//create display object

	if(!display)									//test display object
		return -1;

	al_init_primitives_addon();
	al_install_keyboard();
	al_install_mouse();
	al_init_font_addon();
	al_init_ttf_addon();

	srand(time(NULL));
	InitCar(Player);
	InitTRAFFIC(Enemys, NUM_ENEMY);
	InitFASTCAR(fastcarr);

	
	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 /fps);
	font18 = al_load_font("arial.ttf", 18, 0);

	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_mouse_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));


	al_start_timer(timer);
	
	


	while(!done)
	{
		
		counter++;
		counter2 = counter / 60;
		
		

		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);
		if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			redraw = true;
			if(keys[UP])
				MoveUp(Player);
			if(keys[DOWN])
				MoveDown(Player);
			if(keys[RIGHT])
				MoveRight(Player);
			if(keys[LEFT])
				MoveLeft(Player);


			StartFASTCAR(fastcarr);
			UpdateFASTCAR(fastcarr);
			

			StartTRAFFIC(Enemys, NUM_ENEMY);
			UpdateTRAFFIC(Enemys, NUM_ENEMY);
			CollideTRAFFIC(Enemys, NUM_ENEMY, Player);
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;

				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;

			}
		}

		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
		}

		

		if(redraw && al_is_event_queue_empty)
		{
			

			redraw = false;

			DrawTRAFFIC(Enemys, NUM_ENEMY);
			DrawCar(Player);
			DrawFASTCAR(fastcarr);

			al_draw_filled_rectangle(15,30,90,45,al_map_rgb(255,0,0));
			al_draw_filled_rectangle(90,30,165,45,al_map_rgb(0,0,255));
			al_draw_textf(font18,al_map_rgb(255,255,255),70,10,0, "Heat");

			al_draw_textf(font18,al_map_rgb(255,255,255),300,15,0, "Seconds: %i", counter2);
			
		
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));
		}

		else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = true;
		}

		
	}

	al_destroy_display(display);					//destroy display object

	return 0;
}


void InitFASTCAR(FASTCAR &fastcarr)
{
		fastcarr.ID = FC;
	    fastcarr.live = false;
		fastcarr.speed = 8;
		fastcarr.boundx = 35;
		fastcarr.boundy = 25;
}
void DrawFASTCAR(FASTCAR &fastcarr)
{
			al_draw_filled_rounded_rectangle(fastcarr.x, fastcarr.y, fastcarr.x +70, fastcarr.y +50, fastcarr.x - 4,fastcarr.y - 4,al_map_rgb(255,0,0));

			al_draw_filled_rounded_rectangle(fastcarr.x, fastcarr.y, fastcarr.x +70, fastcarr.y +50, fastcarr.x - 4,fastcarr.y - 4,al_map_rgb(50,50,50));
}
void StartFASTCAR(FASTCAR &fastcarr)
{
		if(!fastcarr.live)
		{
			if(rand() % 500 == 0)
			{
				fastcarr.live = true;
				fastcarr.x = width;
				fastcarr.y = 30 + rand() % (height - 60);
			}
		}
}

void UpdateFASTCAR(FASTCAR &fastcarr)
{

		if(fastcarr.live)
		{
			fastcarr.x -= fastcarr.speed;

			if(fastcarr.x < 0)
				fastcarr.live = false;
		}
}


This is the header file
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
enum IDS{PLAYER, ENEMY1, FC};

struct CAR
{
	int ID;
		int x;
		int y;
		int speed;
		int lives;
		int boundx;
		int boundy;
		int score;
		bool collision;
};

struct TRAFFIC
{
	int ID;
	int x;
	int y;
	bool live;
	int speed;
	int boundx;
	int boundy;
};

struct FASTCAR
{
	int ID;
	int x;
	int y;
	bool live;
	int speed;
	int boundx;
	int boundy;
};

Topic archived. No new replies allowed.