diff --git a/source/tart.c b/source/tart.c index 4096580..f61d6e5 100644 --- a/source/tart.c +++ b/source/tart.c @@ -18,6 +18,10 @@ struct tart_window tart_create_window() { window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},(struct tart_vec2){0,0}); } window.size = term_current_size(); + window.data = malloc((window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100 ); + for(int g = 0; g < (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100; g++) { + window.data[g] = '\0'; + } return window; } @@ -79,7 +83,6 @@ struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { int offset = 0; int i = 0; - window->data = malloc((window->size.x * window->size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100 ); for (int b = 0;b < 0xFF; b++) { if(window->buffers[b].cell_count == 0) continue; @@ -87,7 +90,7 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { for (int x = 0; x < window->buffers[b].size.x; x++) { // add data to window c buffer. struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x]; - char pre[16]; + char pre[20]; int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m", (int)cell.style, cell.foreground, cell.background, cell.display); for(int preIdx = 0; preIdx < size; preIdx++) { window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx]; @@ -104,7 +107,6 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { } } fwrite(window->data, sizeof(char), (window->size.x * window->size.y * sizeof(char))+ 100 , stdout); - free(window->data); return TART_OK; };