From e58aa557e8d2ebd930f549eec98de59de6b63bed Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 17 Mar 2019 14:10:31 -0400 Subject: Only check errors from create calls --- demo.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/demo.c b/demo.c index a5116de..812e5f4 100644 --- a/demo.c +++ b/demo.c @@ -26,8 +26,13 @@ enum { Height = 402, }; +static void fail(const char *prefix) { + fprintf(stderr, "%s: %s\n", prefix, SDL_GetError()); + exit(EXIT_FAILURE); +} + int main(void) { - if (SDL_Init(SDL_INIT_VIDEO) < 0) goto fail; + if (SDL_Init(SDL_INIT_VIDEO) < 0) fail("SDL_Init"); atexit(SDL_Quit); SDL_Window *window; @@ -36,25 +41,27 @@ int main(void) { Width, Height, SDL_WINDOW_ALLOW_HIGHDPI, &window, &render ); - if (error) goto fail; + if (error) fail("SDL_CreateWindowAndRenderer"); int width, height; - if (SDL_GetRendererOutputSize(render, &width, &height) < 0) goto fail; - if (width != Width || height != Height) { - float scaleX = (float)width / Width; - float scaleY = (float)height / Height; - if (SDL_RenderSetIntegerScale(render, SDL_TRUE) < 0) goto fail; - if (SDL_RenderSetScale(render, scaleX, scaleY) < 0) goto fail; + SDL_GetRendererOutputSize(render, &width, &height); + if (width > Width || height > Height) { + SDL_RenderSetIntegerScale(render, SDL_TRUE); + SDL_RenderSetScale( + render, + (float)width / Width, + (float)height / Height + ); } // TODO: Path search/option. SDL_RWops *rw = SDL_RWFromFile("CARDS.DLL", "rb"); - if (!rw) goto fail; + if (!rw) fail("CARDS.DLL"); struct Cards *cards = Cards_Load( rw, Cards_ColorKey | Cards_AlphaCorners | Cards_BlackBorders ); - if (!cards) goto fail; + if (!cards) fail("Cards_Load"); SDL_RWclose(rw); SDL_Texture *textures[Cards_Count]; @@ -62,7 +69,7 @@ int main(void) { textures[i] = NULL; if (!cards->surfaces[i]) continue; textures[i] = SDL_CreateTextureFromSurface(render, cards->surfaces[i]); - if (!textures[i]) goto fail; + if (!textures[i]) fail("SDL_CreateTextureFromSurface"); } Cards_Free(cards); @@ -71,7 +78,7 @@ int main(void) { for (;;) { SDL_Event event; - if (!SDL_WaitEvent(&event)) goto fail; + SDL_WaitEvent(&event); if (event.type == SDL_QUIT) break; if (event.type == SDL_KEYDOWN) { @@ -95,17 +102,12 @@ int main(void) { } } - // TODO: Determine if these checks are really necessary. - if (SDL_SetRenderDrawColor(render, 0x00, 0xAA, 0x55, 0xFF) < 0) goto fail; - if (SDL_RenderClear(render) < 0) goto fail; - if (SDL_RenderCopy(render, textures[card], NULL, &rect) < 0) goto fail; + SDL_SetRenderDrawColor(render, 0x00, 0xAA, 0x55, 0xFF); + SDL_RenderClear(render); + SDL_RenderCopy(render, textures[card], NULL, &rect); SDL_RenderPresent(render); } return EXIT_SUCCESS; - -fail: - fprintf(stderr, "%s\n", SDL_GetError()); - return EXIT_FAILURE; } -- cgit 1.4.1 commit/bin/catsh/catsh.1?id=ec5b37a0939b7da7500e0b1349e1bcbf167e86c3&follow=1'>Simplify ENV default value in catsh.1June McEnroe 2019-04-18Factor out XDG_CONFIG_HOME and XDG_DATA_HOMEJune McEnroe 2019-04-18Clean up catsh configJune McEnroe 2019-04-18Rename cash config to catshJune McEnroe 2019-04-18Rename cash to catshJune McEnroe 2019-04-15Color python imports as StatementJune McEnroe 2019-04-13Add The Demolished ManJune McEnroe 2019-04-07Add AmatkaJune McEnroe 2019-04-03Add Space OperaJune McEnroe 2019-03-22Add An Unkindness of GhostsJune McEnroe 2019-03-14Highlight line continuations in line commentsJune McEnroe 2019-03-14Add The Long Way to a Small Angry PlanetJune McEnroe 2019-03-10Add Bleachers Tiny Desk ConcertJune McEnroe 2019-02-28Add Station ElevenJune McEnroe 2019-02-27Use getsubopt(3) to parse -o options in hiJune McEnroe 2019-02-27Add type and ulimit shell keywordsJune McEnroe 2019-02-27Fix make target pattern whitespace in hiJune McEnroe 2019-02-27Delete extraneous <pre> in html.shJune McEnroe 2019-02-24Use setopt in upJune McEnroe 2019-02-24Add setoptJune McEnroe 2019-02-20Match make targets as TagJune McEnroe 2019-02-20Use $PWD in html.sh to pass absolute path to manJune McEnroe 2019-02-20Factor out html.sh and produce html for all sourcesJune McEnroe 2019-02-20Add Dirk Gently's Holistic Detective AgencyJune McEnroe 2019-02-20Move /opt/pkg after /usr in PATHJune McEnroe 2019-02-20Set man_hard_wrap in nvimJune McEnroe 2019-02-18Use hi -o anchor in upJune McEnroe 2019-02-18Don't match nested parentheses in Tag for CJune McEnroe 2019-02-18Match whitespace between * [] {}June McEnroe 2019-02-18Fix function-like #define regexJune McEnroe 2019-02-18Match Tag in RustJune McEnroe 2019-02-18Match sh functions as TagJune McEnroe 2019-02-18Match Sh and Ss as Tag in mdocJune McEnroe 2019-02-18Match statics and typedefs as TagJune McEnroe 2019-02-18Clean up htmlHeaderJune McEnroe 2019-02-18Remove hi line numberingJune McEnroe 2019-02-18Add Tag class to hiJune McEnroe 2019-02-17Generate HTML with hi -n -f html -o anchorJune McEnroe 2019-02-17Add hi -f html -o anchor for line number linksJune McEnroe 2019-02-17Simplify temp trap in upJune McEnroe 2019-02-17Add line numbers to hiJune McEnroe 2019-02-17Always split spans after newlinesJune McEnroe 2019-02-15Color format specifiers light cyan in vimJune McEnroe 2019-02-15Highlight Interp as yellowJune McEnroe 2019-02-15Highlight strings in sh command substitutionsJune McEnroe 2019-02-15Add nmap gpJune McEnroe 2019-02-14Avoid newline when copying URL to pasteboardJune McEnroe 2019-02-13Add forgotten "sixth" book of H2G2June McEnroe