Game not working with 1 more thing in struct?

I'm making a shooter game and decided I needed another thing in the Bullet struct, so I added it, and all of the sudden the game doesn't work anymore. Even if I add a variable in the struct that does nothing in the program, it doesn't work. I've figured out that the problem is that the server can't understand the player's packet for some reason and just gives it random numbers. If I add one other thing to any other struct the program works fine. It's just if I add something to the Bullet struct it crashes from huge random numbers from the player. I don't think the struct is too big or anything. The player struct is the biggest and doesn't crash the server if I add something to it. Code was too big, so I deleted some. Also, I had to delete a ton of code to get it under the 8000 length limit, so I probably messed up the parenthesis.

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
struct Player
{
	int x, y, ID, weapon, type, frame;
	int gunDis, gunOffX, gunOffY;
	float dir, health;
	bool ready;
	string name, verify;
	ENetPeer *peer;

	int hi;
};

///////////////////BULLET STRUCT HERE////////////////
struct Bullet
{
	float x, y, speed, dir, damage;
	int radius, playerID, life;
	int type, explosive, collidedPlayer;
	bool active;
	//int hi;
	//bool playerCollision;
};
/////////////////////////////////////////////////////

struct Item 
{
	int x;
	int y;
	int type;
};

int main () {

	al_init();
	if (!enet_initialize())
		cout << "Initialized ENet\n";

	ENetAddress address;
	ENetHost * server;
	ENetEvent event;

	address.host = ENET_HOST_ANY;
	address.port = 12345;
	server = enet_host_create(&address, 32, 1, 0, 0);

	if (address.port != NULL)
		cout << "Binded to port " << address.port << endl;
	if (server != NULL)
		cout << "Successfully created ENet Server\n";

	if (server == NULL) {
		cout << "ERROR: Could not create ENet Server " << endl << "Press any key to exit...\n";
		system("pause>nul");
		exit(EXIT_FAILURE);
	}

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

	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / 60.0);

	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	al_start_timer(timer);

	while (!done) {
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		if (ev.type == ALLEGRO_EVENT_TIMER) {
			UpdateBullets(bullets, players, server);
			UpdateGame(gameState, countDown, startTimer, startTimerStart, players, bullets, items, server, resetCount, resetTimerStart, resetTimer);
			
		}

		while (enet_host_service (server, & event, 0) > 0) {
			switch (event.type) {

				case ENET_EVENT_TYPE_RECEIVE:
					{
						//printf("Recieved a packet containing %s\n", event.packet->data);

						if(event.packet->data[0] == 'P') {
							char message[100];
							int messageCount = 0;
							int x;
							int y;
							float dir;
							int ID;
							int frame;

							for(unsigned int i = 1; i < event.packet->dataLength; ++i) {
								message[i] = event.packet->data[i];
							}
							string coords = message;

							istringstream ss(coords);
							string token;

							while(getline(ss, token, ',')) {
								if (messageCount == 1) {
									x = atoi(token.c_str());
								}
								else if (messageCount == 2) {
									y = atoi(token.c_str());
								}
								else if (messageCount == 3) {
									dir = atof(token.c_str());
								}
								else if (messageCount == 4) {
									ID = atoi(token.c_str());
								}
								else if (messageCount == 5) {
									frame = atoi(token.c_str());
								}
								messageCount++;
							}

							cout << "Size: " << players.size() << " X: " << x << " Y: " << y << " ID: " << ID << " Frame: " << frame << endl;

							players[ID].x = x;
							players[ID].y = y;
							players[ID].dir = dir;
							players[ID].frame = frame;
						}
						else if (event.packet->data[0] == 'N') {

							char message[100];
							int messageCount = 0;
							int ID;
							float x;
							float y;
							int type;
							string name;
							string verify;

							for(unsigned int i = 0; i < event.packet->dataLength; ++i) {
								message[i] = event.packet->data[i];
							}
							string coords = message;

							istringstream ss(coords);
							string token;

							while(getline(ss, token, ',')) {
								if (messageCount == 1) {
									ID = atoi(token.c_str());
								}
								else if (messageCount == 2) {
									x = atoi(token.c_str());
								}
								else if (messageCount == 3) {
									y = atoi(token.c_str());
								}
								else if (messageCount == 4) {
									name = token;
								}
								else if (messageCount == 5) {
									type = atoi(token.c_str());
								}
								else if (messageCount == 6) {
									verify = token;
								}
								messageCount++;
							}
							players[ID].name = name;
							players[ID].x = x;
							players[ID].y = y;
							players[ID].weapon = BAZOOKA;
							players[ID].type = type;
							players[ID].ready = false;
							players[ID].verify = "Verified";
							if (players[ID].type == 0) {
								players[ID].gunOffX = 45;
								players[ID].gunOffY = 21;
							}
							else if (players[ID].type == 1) {
								players[ID].gunOffX = 45;
								players[ID].gunOffY = 15;
							}

							players[ID].gunDis = 20;
			
							cout << "Name: " << name << " ID: " << ID << " X: " << x << " Y: " << y << " Type: " << type << endl << endl;
						}
						else if(event.packet->data[0] == 'M') {
							char message[100];
							int messageCount = 0;
							float dir;
							int ID;

							for(unsigned int i = 1; i < event.packet->dataLength; ++i) {
								message[i] = event.packet->data[i];
							}
							string coords = message;

							istringstream ss(coords);
							string token;

							while(getline(ss, token, ',')) {
								if (messageCount == 1) {
									dir = atof(token.c_str());
								}
								else if (messageCount == 2) {
									ID = atoi(token.c_str());
								}
								messageCount++;
							}
							players[ID].dir = dir;
						}
						else if (event.packet->data[0] == 'B') {

							char message[100];
							int messageCount = 0;
							int ID;

							for(unsigned int i = 0; i < event.packet->dataLength; ++i) {
								message[i] = event.packet->data[i];
							}
							string coords = message;

							istringstream ss(coords);
							string token;

							while(getline(ss, token, ',')) {
								ID = atoi(token.c_str());

								}
							}
						}
						if(event.packet->data[0] == 'R') {
							char message[100];
							int messageCount = 0;
							int ID;

							for(unsigned int i = 1; i < event.packet->dataLength; ++i) {
								message[i] = event.packet->data[i];
							}
							string coords = message;

							istringstream ss(coords);
							string token;

							while(getline(ss, token, ',')) {
								ID = atoi(token.c_str());
							}
							players[ID].ready = true;
						}

						enet_packet_destroy (event.packet);
					}
					break;

				case ENET_EVENT_TYPE_DISCONNECT:
					printf ("%s disconected.\n", event.peer -> data);
					event.peer -> data = NULL;
					for (unsigned int i = 0; i < players.size(); i++) {
						if(players[i].peer->address.host == event.peer->address.host && players[i].peer->address.port == event.peer->address.port) {
							players.erase(players.begin() + i);
							cout << "Size: " << players.size() << endl;
							break;
						}
					}
					break;
			}
		}
		string playerPacket = "";
		for (unsigned int i = 0; i < players.size(); i++) {
			char packet[256];
			string buf;
			sprintf_s(packet, sizeof(packet), "P,%i,%i,%i,%f,%s,%f,%i,%i,%i;", players[i].ID, players[i].x, players[i].y, players[i].dir, players[i].name.c_str(), players[i].health, players[i].type, players[i].frame, players[i].weapon);
			buf = packet;
			playerPacket = playerPacket + buf;
		}
		const char *packetBuf = playerPacket.c_str();
		ENetPacket *p = enet_packet_create((char*)packetBuf, strlen(packetBuf)+1, ENET_PACKET_FLAG_UNSEQUENCED);
		//printf("Sent a packet to client containing %s\n", playerPacket);
		enet_host_broadcast(server, 0, p);
	}
		

	enet_host_destroy(server);
}

This is the only place in all the code you posted that has Bullet:
1
2
///////////////////BULLET STRUCT HERE////////////////
struct Bullet

Where do you even use it?
I had to delete like half of the code to get it under the limit. I deleted all the functions. That's why you don't see updating bullets and stuff. But it doesn't even matter if the function is doing anything. If I add int Test to the strict, the program doesn't work right. If I add anything to any other struts, it works fine. If you need the whole code, I'll put it in a couple replies.
Well if adding something to Bullet breaks the program, the problem must be related to Bullet somehow either directly or indirectly. I don't know anything about Allegro or the server stuff, that shouldn't matter. Just because adding stuff to other parts doesn't break it is irrelevant and if nothing else should point out even more that there is something wrong with Bullet and/or how you are using it. There is no reason to post 1000 lines of code, just narrow it down to where the problem might be.
I tried commenting out all the update functions and everything that has to do with bullets, but still adding any new variable to the Bullet struct causes the server to not be able to figure out the players position, and just gives it random numbers, and crashes itself. I can't find any reason why it would make that happen...
Okay... I changed nothing with it, but for some reason it decided it wanted to stop being weird and works now.
Topic archived. No new replies allowed.