summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui.c12
1 files 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);