diff --git a/src/engine.c b/src/engine.c index b74f340..0afc777 100644 --- a/src/engine.c +++ b/src/engine.c @@ -216,10 +216,10 @@ static int digits_ceiling(unsigned int n) struct gamestate* gamestate_init(int argc, char **argv) { struct gameoptions *opt = gameoptions_default(); - if (argc != 0) parse_options(opt, argc, argv); - if (!opt) return NULL; + if (argc != 0) parse_options(opt, argc, argv); + srand(time(NULL)); struct gamestate *g = malloc(sizeof(struct gamestate)); diff --git a/src/engine.h b/src/engine.h index 3f9310f..0d50fad 100644 --- a/src/engine.h +++ b/src/engine.h @@ -2,6 +2,7 @@ #define ENGINE_H #include +#include #include "options.h" #define fatal(msg)\ diff --git a/src/gfx_curses.c b/src/gfx_curses.c index 7487877..4db2467 100644 --- a/src/gfx_curses.c +++ b/src/gfx_curses.c @@ -26,6 +26,8 @@ struct gfx_state* gfx_init(struct gamestate *g) refresh(); struct gfx_state *s = malloc(sizeof(struct gfx_state)); + if (!s) return NULL; + s->window_height = g->opts->grid_height * (g->print_width + 2) + 3; s->window_width = g->opts->grid_width * (g->print_width + 2) + 1; s->window = newwin(s->window_height, s->window_width, 1, 1); diff --git a/src/main.c b/src/main.c index 29b0a96..c5c62cd 100644 --- a/src/main.c +++ b/src/main.c @@ -14,10 +14,18 @@ void draw_then_sleep(struct gfx_state *s, struct gamestate *g) int main(int argc, char **argv) { struct gamestate *g = gamestate_init(argc, argv); + if (!g) { + fatal("failed to allocate gamestate"); + } + struct gfx_state *s = NULL; - if (g->opts->interactive) + if (g->opts->interactive) { s = gfx_init(g); + if (!s) { + fatal("failed to allocate gfx state"); + } + } int game_running = true; while (game_running) {