commit 753cd63c53a67a1d45203ca7e9ae8c49747c3328
parent adb9c001034df1ee3948320b1022b3b4f2ccdc8a
Author: Amin Mesbah <mesbahamin@gmail.com>
Date: Thu, 26 Oct 2017 21:25:30 -0700
Fix hanging bug caused by uninitialized variables
The game would sometimes appear to init and just hang, not processing
any new input. This would only happen some of the time. Digging revealed
crazy values for the vector lengths and angles.
Of course! They were never initialized. Moving the initialization to
functions will help prevent this.
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -16,9 +16,6 @@ void game_init(struct GameState *game_state, int field_width, int field_height)
return;
}
- game_state->view.dx = 0;
- game_state->view.dy = 0;
- game_state->view.zoom = 1;
game_state->player.angle = 0;
game_state->player.speed = 0;
game_state->player.mass = 10;
@@ -26,6 +23,15 @@ void game_init(struct GameState *game_state, int field_width, int field_height)
game_state->player.x = field_width / 2;
game_state->player.y = field_height / 2;
game_state->player.color = 0x888888;
+ game_state->thrust_vector01.angle = 0;
+ game_state->thrust_vector01.length = 0;
+ game_state->thrust_vector02.angle = 0;
+ game_state->thrust_vector02.length = 0;
+ game_state->thrust_vector_sum.angle = 0;
+ game_state->thrust_vector_sum.length = 0;
+ game_state->view.dx = 0;
+ game_state->view.dy = 0;
+ game_state->view.zoom = 1;
}