diff options
-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); |