diff options
author | kdx <kikoodx@paranoici.org> | 2023-05-03 13:31:10 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-05-03 13:31:10 +0200 |
commit | 398c0bf3fe66da5c050c01580612c20bce03038a (patch) | |
tree | c282502c57c58f912dc6ec3f34a2fe7296db32af | |
parent | b2a3baf7f6ebbb5442443634f2faac4953c7b732 (diff) | |
download | px-398c0bf3fe66da5c050c01580612c20bce03038a.tar.gz |
handle SDL_LockTexture failure
-rw-r--r-- | src/px.c | 9 | ||||
-rw-r--r-- | src/px.h | 8 |
2 files changed, 11 insertions, 6 deletions
@@ -40,7 +40,7 @@ pxInit(void) PX_WIDTH, PX_HEIGHT); if (pxtexture == NULL) { fprintf(stderr, "%s\n", SDL_GetError()); - return 1; + return -1; } return 0; } @@ -54,12 +54,15 @@ pxDeinit(void) } } -void +int pxFlip(void) { uint8_t *pixels = NULL; int pitch = 0; - SDL_LockTexture(pxtexture, NULL, (void **)&pixels, &pitch); + if (SDL_LockTexture(pxtexture, NULL, (void **)&pixels, &pitch)) { + fprintf(stderr, "%s\n", SDL_GetError()); + return -1; + } for (int y = 0; y < PX_HEIGHT; y++) { for (int x = 0; x < PX_WIDTH; x++) { @@ -52,14 +52,16 @@ typedef struct { extern PxCol pxbuf[PX_WIDTH * PX_HEIGHT]; extern PxPal pxpal[256]; -/* Return -1 on error. Should be called after TZR_Init. */ +/* Return -1 on error. + * Should be called after TZR_Init. */ int pxInit(void); /* Should be called before TZR_Quit. */ void pxDeinit(void); -/* Should be called between TZR_DrawBegin and TZR_DrawEnd. */ -void pxFlip(void); +/* Return -1 on error. + * Should be called between TZR_DrawBegin and TZR_DrawEnd. */ +int pxFlip(void); /*** DRAW ***/ /* Fill the clipping region with color 'c'. */ |