diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | die.c | 16 | ||||
| -rw-r--r-- | die.h | 17 | ||||
| -rw-r--r-- | main.c | 9 |
4 files changed, 31 insertions, 13 deletions
@@ -3,7 +3,7 @@ SDL_HEADERS=/usr/include/SDL2 CFLAGS=-g -Wall -pedantic -std=c99 $$(sdl2-config --cflags) LFLAGS=$$(sdl2-config --libs) -findgame: main.o world.o random.o generator.o save.o +findgame: main.o world.o random.o generator.o save.o die.o $(CC) -o $@ $^ $(LFLAGS) main.o: world.h random.h save.h @@ -0,0 +1,16 @@ +#include <SDL.h> + +void die(void) { + while (1) { + // draw error message text? + SDL_Event e; + while (SDL_WaitEvent(&e)) SDL_Delay(1); + } +} + +void sdl_error_assert(SDL_bool condition) { + if (!condition) { + SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "%s", SDL_GetError()); + die(); + } +} @@ -1,13 +1,12 @@ +#ifndef DIE_H +#define DIE_H + #include <SDL.h> -#include <stdlib.h> +void die(void); +void sdl_error_assert(SDL_bool condition); -#define die(...) (SDL_Log(__VA_ARGS__), abort()) -static inline void sdl_error_assert(SDL_bool condition) { - if (!condition) { - SDL_Log("%s", SDL_GetError()); - // banish to hell forever - abort(); - } -} +#define die(...) (SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, __VA_ARGS__), die()) #define sdl_error_assert(c) (sdl_error_assert(c && SDL_TRUE)) + +#endif @@ -68,19 +68,22 @@ static int run() { int main(int argc, char *argv[]) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { - SDL_Log("error initializing SDL: %s", SDL_GetError()); + SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, + "error initializing SDL: %s", SDL_GetError()); return 1; } win = SDL_CreateWindow("find", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 960, 720, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (!win) { - SDL_Log("error creating window: %s", SDL_GetError()); + SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, + "error creating window: %s", SDL_GetError()); return 1; } rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_PRESENTVSYNC); if (!rend) { - SDL_Log("error creating renderer: %s", SDL_GetError()); + SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, + "error creating renderer: %s", SDL_GetError()); return 1; } |
