From 6ff3f731e2b5cb790cd96ce0a8dd562fbb246497 Mon Sep 17 00:00:00 2001 From: "S. Gilles" Date: Sat, 3 Dec 2016 13:40:05 -0500 Subject: [PATCH] Check more return codes --- clav.c | 41 ++++++++++-------- ui-sdl.c | 149 +++++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 116 insertions(+), 74 deletions(-) diff --git a/clav.c b/clav.c index f9cb5ad..0ff2724 100644 --- a/clav.c +++ b/clav.c @@ -88,7 +88,7 @@ int main(int argc, char **argv) quiver_add_vertex(&q, &v1, "1", 2, 100, 100, 0); quiver_add_vertex(&q, &v2, "2", 1, 170, -70, 0); quiver_add_vertex(&q, &v1b, "1'", 2, -140, 100, 0); - quiver_add_vertex(&q, &v2b, "2'", 1, -110, -70, 0); + quiver_add_vertex(&q, &v2b, "2'", 1, -140, -70, 0); quiver_add_vertex(&q, &v12, "12", 2, -350, -150, 0); quiver_add_vertex(&q, &v21, "21", 1, -150, -350, 0); quiver_add_vertex(&q, &v32, "32", 1, 350, -150, 0); @@ -103,34 +103,39 @@ int main(int argc, char **argv) quiver_add_to_edge(&q, v23, v32, 1, 2, 0); quiver_add_to_edge(&q, v10, v01, 1, 2, 0); quiver_add_to_edge(&q, v30, v03, 1, 2, 0); + quiver_add_to_edge(&q, v01, v1b, 1, 1, 0); + quiver_add_to_edge(&q, v03, v1, 1, 1, 0); + quiver_add_to_edge(&q, v0, v1b, 1, 1, 0); + quiver_add_to_edge(&q, v0, v32, 1, 1, 0); + quiver_add_to_edge(&q, v10, v21, 1, 1, 0); + quiver_add_to_edge(&q, v12, v1b, 1, 1, 0); + quiver_add_to_edge(&q, v1b, v2b, 1, 1, 0); + quiver_add_to_edge(&q, v1b, vinf, 1, 1, 0); + quiver_add_to_edge(&q, v1, v2, 1, 1, 0); + quiver_add_to_edge(&q, v1, v30, 1, 1, 0); quiver_add_to_edge(&q, v21, v2b, 1, 1, 0); quiver_add_to_edge(&q, v23, v1, 1, 1, 0); - quiver_add_to_edge(&q, v12, v1b, 1, 1, 0); - quiver_add_to_edge(&q, v2b, v12, 1, 1, 0); quiver_add_to_edge(&q, v2b, v0, 1, 1, 0); quiver_add_to_edge(&q, v2b, v10, 1, 1, 0); - quiver_add_to_edge(&q, v0, v32, 1, 1, 0); - quiver_add_to_edge(&q, v0, v1b, 1, 1, 0); - quiver_add_to_edge(&q, v32, v2, 1, 1, 0); - quiver_add_to_edge(&q, v1b, vinf, 1, 1, 0); - quiver_add_to_edge(&q, v1b, v2b, 1, 1, 0); - quiver_add_to_edge(&q, v1, v30, 1, 1, 0); - quiver_add_to_edge(&q, v1, v2, 1, 1, 0); + quiver_add_to_edge(&q, v2b, v12, 1, 1, 0); quiver_add_to_edge(&q, v2, v0, 1, 1, 0); - quiver_add_to_edge(&q, v2, v23, 1, 1, 0); quiver_add_to_edge(&q, v2, v03, 1, 1, 0); - quiver_add_to_edge(&q, v10, v21, 1, 1, 0); - quiver_add_to_edge(&q, vinf, v1, 1, 1, 0); - quiver_add_to_edge(&q, vinf, v01, 1, 1, 0); + quiver_add_to_edge(&q, v2, v23, 1, 1, 0); quiver_add_to_edge(&q, v30, vinf, 1, 1, 0); - quiver_add_to_edge(&q, v01, v1b, 1, 1, 0); - quiver_add_to_edge(&q, v03, v1, 1, 1, 0); + quiver_add_to_edge(&q, v32, v2, 1, 1, 0); + quiver_add_to_edge(&q, vinf, v01, 1, 1, 0); + quiver_add_to_edge(&q, vinf, v1, 1, 1, 0); /* Mutations */ - /* quiver_mutate(&q, v0, 0); quiver_mutate(&q, vinf, 0); - */ + quiver_mutate(&q, v1, 0); + quiver_mutate(&q, v2, 0); + quiver_mutate(&q, v1b, 0); + quiver_mutate(&q, v2b, 0); + quiver_mutate(&q, v0, 0); + quiver_mutate(&q, v1, 0); + quiver_mutate(&q, v1b, 0); if ((ret = ui_respond_quiver_change())) { goto done; diff --git a/ui-sdl.c b/ui-sdl.c index 41b3049..7c92515 100644 --- a/ui-sdl.c +++ b/ui-sdl.c @@ -347,7 +347,7 @@ static int eq_push(struct ui_event *in) /* Initialize SDL */ int ui_init(struct quiver *i_q) { - int sv_err; + int ret; q = i_q; @@ -384,26 +384,34 @@ int ui_init(struct quiver *i_q) return ENOMEDIUM; } - if ((sv_err = load_fonts())) { - return sv_err; + if ((ret = load_fonts())) { + goto done; } - if ((sv_err = render_vertex_names())) { - return sv_err; + if ((ret = render_vertex_names())) { + goto done; + } + + if ((ret = SDL_SetRenderDrawColor(sdl_renderer, color_bg.r, color_bg.g, + color_bg.b, color_bg.a))) { + fprintf(stderr, L("SDL_SetRenderDrawColor(): %s\n"), + SDL_GetError()); + goto done; + } + + if ((ret = SDL_RenderClear(sdl_renderer))) { + fprintf(stderr, L("SDL_RenderClear(): %s\n"), SDL_GetError()); + goto done; } - SDL_SetRenderDrawColor(sdl_renderer, color_bg.r, color_bg.g, color_bg.b, - color_bg.a); - SDL_RenderClear(sdl_renderer); SDL_RenderPresent(sdl_renderer); react_to_window_resized(); /* Set up queue for returning data */ if (!(eq_buf = calloc(2, sizeof *eq_buf))) { - sv_err = errno; + ret = errno; perror(L("malloc")); - - return sv_err; + goto done; } eq_len = 2; @@ -412,8 +420,9 @@ int ui_init(struct quiver *i_q) /* Sines and cosines for drawing circles */ precalc_trig(); +done: - return 0; + return ret; } /* Deal with the fact that the quiver was changed */ @@ -446,19 +455,6 @@ int ui_teardown(void) /* Record that a frame has been started */ int ui_start_frame(void) { - frame_start_ticks = SDL_GetTicks(); - - /* XXX: move most of ui_finish_frame() here - all but the renderpresent */ - return 0; -} - -/* Draw a frame, possibly sleeping for framelimit */ -int ui_finish_frame(void) -{ - Uint32 now = 0; - Uint32 elapsed_time = 0; - SDL_Event sdl_e = { 0 }; - struct ui_event ui_e = { 0 }; int ret = 0; struct vertex *v; struct rational *eij; @@ -478,6 +474,8 @@ int ui_finish_frame(void) int tex_w; int tex_h; + frame_start_ticks = SDL_GetTicks(); + /* Draw the damn thing */ SDL_SetRenderDrawColor(sdl_renderer, color_bg.r, color_bg.g, color_bg.b, color_bg.a); @@ -499,31 +497,38 @@ int ui_finish_frame(void) /* This is the (eij)/dj = -(eji)/di condition */ if (eij->p * q->v[i].fatness * eji->q != -eji->p * q->v[j].fatness * eij->q) { - SDL_SetRenderDrawColor(sdl_renderer, - color_e_abnormal.r, - color_e_abnormal.g, - color_e_abnormal.b, - color_e_abnormal.a); + ret = SDL_SetRenderDrawColor(sdl_renderer, + color_e_abnormal.r, + color_e_abnormal.g, + color_e_abnormal.b, + color_e_abnormal.a); } else if (abs(eij->p) * d == q->v[j].fatness * eij->q) { - SDL_SetRenderDrawColor(sdl_renderer, - color_e_normal.r, - color_e_normal.g, - color_e_normal.b, - color_e_normal.a); + ret = SDL_SetRenderDrawColor(sdl_renderer, + color_e_normal.r, + color_e_normal.g, + color_e_normal.b, + color_e_normal.a); } else if (2 * abs(eij->p) * d == q->v[j].fatness * eij->q) { - SDL_SetRenderDrawColor(sdl_renderer, - color_e_half.r, - color_e_half.g, - color_e_half.b, - color_e_half.a); + ret = SDL_SetRenderDrawColor(sdl_renderer, + color_e_half.r, + color_e_half.g, + color_e_half.b, + color_e_half.a); } else { - SDL_SetRenderDrawColor(sdl_renderer, - color_e_abnormal.r, - color_e_abnormal.g, - color_e_abnormal.b, - color_e_abnormal.a); + ret = SDL_SetRenderDrawColor(sdl_renderer, + color_e_abnormal.r, + color_e_abnormal.g, + color_e_abnormal.b, + color_e_abnormal.a); + } + + if (ret) { + fprintf(stderr, L( + "SDL_SetRenderDrawColor(): %s\n"), + SDL_GetError()); + goto done; } if ((ret = internal_to_pixel_xy(q->v[i].x, q->v[i].y, @@ -536,7 +541,12 @@ int ui_finish_frame(void) goto done; } - SDL_RenderDrawLine(sdl_renderer, cx, cy, cx2, cy2); + if ((ret = SDL_RenderDrawLine(sdl_renderer, cx, cy, cx2, + cy2))) { + fprintf(stderr, L("SDL_RenderDrawLine(): %s\n"), + SDL_GetError()); + goto done; + } if (cx == cx2) { theta = (cy2 > cy) ? M_PI / 2.0 : -M_PI / 2.0; @@ -552,12 +562,25 @@ int ui_finish_frame(void) cy = (cy + cy2) / 2; cx2 = cx + arrow_length * cos(theta + arrow_angle); cy2 = cy + arrow_length * sin(theta + arrow_angle); - SDL_RenderDrawLine(sdl_renderer, cx, cy, cx2, cy2); - SDL_RenderDrawLine(sdl_renderer, cx, cy, cx + - arrow_length * cos(theta - - arrow_angle), cy + - arrow_length * sin(theta - - arrow_angle)); + + if ((ret = SDL_RenderDrawLine(sdl_renderer, cx, cy, cx2, + cy2))) { + fprintf(stderr, L("SDL_RenderDrawLine(): %s\n"), + SDL_GetError()); + goto done; + } + + if ((ret = SDL_RenderDrawLine(sdl_renderer, cx, cy, cx + + arrow_length * cos(theta - + arrow_angle), + cy + + arrow_length * sin(theta - + arrow_angle)))) + { + fprintf(stderr, L("SDL_RenderDrawLine(): %s\n"), + SDL_GetError()); + goto done; + } } } @@ -609,16 +632,16 @@ int ui_finish_frame(void) if (j >= vertex_names_len) { fprintf(stderr, L( "render_vertex_names() was not called, somehow\n")); - - return EINVAL; + ret = EINVAL; + goto done; } if (SDL_QueryTexture(vertex_names[j], &dummy_format, &dummy_access, &tex_w, &tex_h)) { fprintf(stderr, L("SDL_QueryTexture(): %s\n"), SDL_GetError()); - - return ENOMEDIUM; + ret = ENOMEDIUM; + goto done; } r.x = cx - tex_w / 2; @@ -628,6 +651,20 @@ int ui_finish_frame(void) SDL_RenderCopy(sdl_renderer, vertex_names[j], 0, &r); } +done: + + return ret; +} + +/* Draw a frame, possibly sleeping for framelimit */ +int ui_finish_frame(void) +{ + struct ui_event ui_e = { 0 }; + SDL_Event sdl_e = { 0 }; + Uint32 elapsed_time = 0; + Uint32 now = 0; + int ret = 0; + SDL_RenderPresent(sdl_renderer); /* Handle user input */ -- 2.11.4.GIT