summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruntir_l <87096069+untir-l@users.noreply.github.com>2022-06-11 16:04:29 +0000
committeruntir_l <87096069+untir-l@users.noreply.github.com>2022-06-11 16:05:42 +0000
commit4f6198b965357ca63daf24d7767be715987fe58b (patch)
tree36efc680d9848005dc020acd5676dde349360403
parent2aa35e2c108f954949ec001f1e33846379e7cc98 (diff)
downloadhitomezashi-4f6198b965357ca63daf24d7767be715987fe58b.tar
hitomezashi-4f6198b965357ca63daf24d7767be715987fe58b.tar.gz
hitomezashi-4f6198b965357ca63daf24d7767be715987fe58b.zip
Web: clean up code, fix memory leak
-rw-r--r--web/hitomezashi_web.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/web/hitomezashi_web.c b/web/hitomezashi_web.c
index 413f727..994eaa5 100644
--- a/web/hitomezashi_web.c
+++ b/web/hitomezashi_web.c
@@ -40,24 +40,25 @@ void EMSCRIPTEN_KEEPALIVE main_loop(void) {
const Uint32 fg_colour = hitomezashi_web_get_fg_colour();
const Uint32 bg_colour = hitomezashi_web_get_bg_colour();
- // If any of these are 0, input was invalid
- if (!(x_pattern_len && y_pattern_len && gap && line_thickness))
- return;
-
- struct Hitomezashi_State state;
- hitomezashi_state_init(&state, x_pattern_len, y_pattern_len, x_pattern,
- y_pattern, gap, line_thickness, fg_colour, bg_colour);
- SDL_SetWindowSize(window, state.output_width, state.output_height);
- hitomezashi_draw(&state);
-
- SDL_BlitSurface(state.surface, NULL, SDL_GetWindowSurface(window), NULL);
- SDL_UpdateWindowSurface(window);
+ // If input was valid (if any of these are 0 it was invalid)
+ if (x_pattern_len && y_pattern_len && gap && line_thickness) {
+ struct Hitomezashi_State state;
+ hitomezashi_state_init(&state, x_pattern_len, y_pattern_len, x_pattern,
+ y_pattern, gap, line_thickness, fg_colour,
+ bg_colour);
+ SDL_SetWindowSize(window, state.output_width, state.output_height);
+ hitomezashi_draw(&state);
+
+ SDL_BlitSurface(state.surface, NULL, SDL_GetWindowSurface(window), NULL);
+ SDL_UpdateWindowSurface(window);
+
+ SDL_FreeSurface(state.surface);
+ }
free((char *)x_pattern_raw);
free((char *)y_pattern_raw);
free((char *)x_pattern);
free((char *)y_pattern);
- SDL_FreeSurface(state.surface);
}
EM_JS(char *, hitomezashi_web_get_x_pattern, (void), {