summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-05-03 13:31:10 +0200
committerkdx <kikoodx@paranoici.org>2023-05-03 13:31:10 +0200
commit398c0bf3fe66da5c050c01580612c20bce03038a (patch)
treec282502c57c58f912dc6ec3f34a2fe7296db32af
parentb2a3baf7f6ebbb5442443634f2faac4953c7b732 (diff)
downloadpx-398c0bf3fe66da5c050c01580612c20bce03038a.tar.gz
handle SDL_LockTexture failure
-rw-r--r--src/px.c9
-rw-r--r--src/px.h8
2 files changed, 11 insertions, 6 deletions
diff --git a/src/px.c b/src/px.c
index 5c1af9b..694c789 100644
--- a/src/px.c
+++ b/src/px.c
@@ -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++) {
diff --git a/src/px.h b/src/px.h
index f413bdc..cc59c7f 100644
--- a/src/px.h
+++ b/src/px.h
@@ -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'. */