From 85b9e3531416f5075c85869e6b915fa48e214689 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 23 Jan 2023 20:55:55 +0100 Subject: Implement GUI init and deinit functions --- gui.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gui.c b/gui.c index cb26990..1c107da 100644 --- a/gui.c +++ b/gui.c @@ -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); -- cgit v1.2.3-70-g09d2