diff options
author | xengineering <me@xengineering.eu> | 2023-01-23 20:55:55 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-01-23 20:55:55 +0100 |
commit | 85b9e3531416f5075c85869e6b915fa48e214689 (patch) | |
tree | 4b4c9c9e1c8c7c66e3507df1040da36a69149342 | |
parent | 5d57490507ea04c8739ee2a51639c86d1eda3cd2 (diff) | |
download | limox-85b9e3531416f5075c85869e6b915fa48e214689.tar limox-85b9e3531416f5075c85869e6b915fa48e214689.tar.zst limox-85b9e3531416f5075c85869e6b915fa48e214689.zip |
Implement GUI init and deinit functions
-rw-r--r-- | gui.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -42,9 +42,17 @@ struct GuiContext *init() { ctx->quit = false; ctx->xmpp_fd = -1; + ctx->pixels = malloc(sizeof(uint32_t) * 640 * 480); + memset(ctx->pixels, 255, 640 * 480 * sizeof(uint32_t)); + return ctx; } +void deinit(struct GuiContext *ctx) { + free(ctx->pixels); + free(ctx); +} + void gui_run(void) { struct GuiContext *ctx = init(); @@ -63,8 +71,6 @@ void gui_run(void) { ctx->renderer = SDL_CreateRenderer(ctx->window, -1, 0); ctx->texture = SDL_CreateTexture(ctx->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, 640, 480); - ctx->pixels = malloc(sizeof(uint32_t) * 640 * 480); - memset(ctx->pixels, 255, 640 * 480 * sizeof(uint32_t)); // handle failed window creation if (ctx->window == NULL) { @@ -95,7 +101,7 @@ void gui_run(void) { SDL_DestroyWindow(ctx->window); } - free(ctx->pixels); + deinit(ctx); // TODO this seems to end in memory access errors but ... why? //SDL_DestroyTexture(texture); |