problem with crt0dat.c, know what it is?

So my problem is that when I run my program, it seems to start up without a hitch. then it stops right before the while(!done), and doesn't display anything. and clicking the x to close the window doesn't work, and pressing esc doesn't work. So I close the console window and continue debugging. Then it gives me an error in a file called crt0dat.c which I didn't create and I'm sure some of you know that. the line that it tells me it has a problem is this onexitbegin_new = (_PVFV *) DecodePointer(__onexitbegin); I have no clue what this file is or what the problem is. here is my main
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_primitives.h>
#include <list>

#include "GameObject.h"
#include "GoodDude.h"
#include "BadGuy.h"
#include "Background.h"
#include "Globals.h"

bool keys[] = {false, false, false, false, false};
enum KEYS{UP, DOWN, LEFT, RIGHT, SPACE};

//globals
GoodDude *dude;
BadGuy *bad;
std::list<GameObject *> objects;
std::list<GameObject *>::iterator iter;
std::list<GameObject *>::iterator iter2;
Background *titleScreen;
Background *lostScreen;
Background *wonScreen;

//prototypes
void __cdecl TalkLife();
// void TakeLife() __attribure __((cdecl));
void __cdecl ScorePoint();
// void ScorePoint() __attribute __((cdecl));
void ChangeState(int &state, int newState);

int main(int argc, char **argv)
{
	bool done = false;
	bool render = false;

	float gameTime = 0;
	int frames = 0;
	int gameFPS = 0;

	
	dude = new GoodDude();
	bad = new BadGuy();

	int state = -1;

	ALLEGRO_BITMAP *dudeImage = NULL;
	ALLEGRO_BITMAP *badImage = NULL;
	ALLEGRO_BITMAP *bgImage = NULL;
	ALLEGRO_BITMAP *titleImage = NULL;
	ALLEGRO_BITMAP *lostImage = NULL;
	ALLEGRO_BITMAP *wonImage = NULL;

	
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer;

	
	if(!al_init())
		return -1;

	display = al_create_display(WIDTH, HEIGHT);

	if(!display)
		return -1;

	
	al_install_keyboard();
	al_init_image_addon();
	al_init_primitives_addon();

	
	bgImage = al_load_bitmap("DemoBackground.png");

	Background *bg = new Background(bgImage);
	objects.push_back(bg);

	dudeImage = al_load_bitmap("demospritesheet.png");
	al_convert_mask_to_alpha(dudeImage, al_map_rgb(15, 156, 255));
	dude->Init(dudeImage);

	objects.push_back(dude);

	badImage = al_load_bitmap("badguyspritesheet.png");
	al_convert_mask_to_alpha(badImage, al_map_rgb(15, 156, 255));
	bad->Init(badImage);

	objects.push_back(bad);

	titleImage = al_load_bitmap("demoTitle.png");
	lostImage = al_load_bitmap("demoLost.png");
	wonImage = al_load_bitmap("demoWon.png");

	titleScreen = new Background(titleImage);
	lostScreen = new Background(lostImage);
	wonScreen = new Background(wonImage);

	ChangeState(state, TITLE);

	srand(time(NULL));
	
	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / 60);

	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_keyboard_event_source());

	al_start_timer(timer);
	gameTime = al_current_time();
	while(!done);
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		
		if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;
				if(state == TITLE)
					ChangeState(state, PLAYING);
				else if(state == LOST)
				{
					ChangeState(state, PLAYING);
				}
				else if(state == WON)
					ChangeState(state, PLAYING);
				break;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			}
		}
		
		else if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			render = true;

			
			frames++;
			if(al_current_time() - gameTime >=1)
			{
				gameTime = al_current_time();
				gameFPS = frames;
				frames = 0;
			}
			
			if(state == PLAYING)
			{
				if(keys[UP])
					dude->MoveUp();
				else if(keys[DOWN])
					dude->MoveDown();
				else
					dude->ResetAnimation(1);

				if(keys[LEFT])
					dude->MoveLeft();
				else if(keys[RIGHT])
					dude->MoveRight();
				else
					dude->ResetAnimation(1);

				
				for(iter = objects.begin(); iter != objects.end(); ++iter)
					(*iter)->Update();

				
				for(iter = objects.begin(); iter != objects.end(); ++iter)
				{
					if( ! (*iter)->Collidable() ) continue;

					for(iter2 = iter; iter2 != objects.end(); ++iter2)
					{
						if( !(*iter2)->Collidable() ) continue;
						if( (*iter)->GetID() == (*iter2)->GetID()) continue;

						if( (*iter)->CheckCollisions( (*iter2)))
						{
							(*iter)->Collided( (*iter2)->GetID());
							(*iter2)->Collided( (*iter)->GetID());
						}
					}
				}

				if(dude->GetLives() <= 0)
					ChangeState(state, LOST);

				if(dude->GetScore() >= 3)
					ChangeState(state, WON);
			}

				
				for(iter = objects.begin(); iter != objects.end(); )
				{
					if(! (*iter)->GetAlive())
					{
						delete(*iter);
						iter = objects.erase(iter);
					}
					else
						iter++;
				}
			}

			
			if(render && al_is_event_queue_empty(event_queue))
			{
				render = false;

				
				if(state == TITLE)
				{
					titleScreen->Render();
				}
				else if(state == PLAYING)
				{
					for(iter = objects.begin(); iter != objects.end(); ++iter)
						(*iter)->Render();
				}
				else if(state == LOST)
				{
					lostScreen->Render();
				}
				else if(state == WON)
				{
					wonScreen->Render();
				}

				
				al_flip_display();
				al_clear_to_color(al_map_rgb(0, 0, 0));
			}
		}

		
		for(iter = objects.begin(); iter != objects.end(); )
		{
			(*iter)->Destroy();
			delete (*iter);
			iter = objects.erase(iter);
		}

		titleScreen->Destroy();
		lostScreen->Destroy();
		wonScreen->Destroy();
		delete titleScreen;
		delete lostScreen;
		delete wonScreen;

		al_destroy_bitmap(badImage);
		al_destroy_bitmap(dudeImage);
		al_destroy_bitmap(bgImage);
		al_destroy_bitmap(titleImage);
		al_destroy_bitmap(lostImage);
		al_destroy_bitmap(wonImage);

		
		al_destroy_timer(timer);
		al_destroy_event_queue(event_queue);
		al_destroy_display(display);

		return 0;
}

void __cdecl TakeLife()
{
	dude->LoseLife();
}
void __cdecl ScorePoint()
{
	dude->AddPoint();
}

void ChangeState(int &state, int newState)
{
	if(state == TITLE)
	{}
	else if(state == PLAYING)
	{
		for(iter = objects.begin(); iter != objects.end(); ++iter)
		{
			if((*iter)->GetID() != PLAYER && (*iter)->GetID() != MISC)
				(*iter)->SetAlive(false);
		}
	}
	else if(state == LOST)
	{}

	state = newState;

	if(state == TITLE)
	{}
	else if(state == PLAYING)
	{
		dude->Init();
		bad->Init();
	}
	else if(state == LOST)
	{}
	else if(state == WON)
	{}
}



if you have any clue what that file is or what the problem is please let me know. also if you need to see more, or if you need something explained, just say so.
Last edited on
You probably have some kind of bad pointer somewhere. That's about all I can tell you without seeing code.

If you can post the function that the program is crashing in, that would help. (I mean the function you wrote. The problem is not in that crt0dat.c file)
Last edited on
well i edited it and put my main up there, but i was thinking it was a bad pointer but the problem is that the program doesn't crash necessarily, the problem pops up after I close the console window, when I set a break point at the while(!done) line (line 111) it breaks when it gets there but nothing happens when I try to step in or over does that tell you anything?
while(!done);

The semicolon there ends the loop. That is an infinite loop. That'll deadlock the program.
well..... that's just nuts, I knew that, but didn't even really notice it. now it makes sense why Visual C++ was having a problem with the spacing of my { things when I was writing it. thank you so very much.
Topic archived. No new replies allowed.