Skip to content

Commit a15c14f

Browse files
committed
sdl2: include + SDL_CHECK add action
include inttypes.h SDL_CHECK can now have an optional action (using ellipsis) + handle return value of SDL_LockTesxture using that (currently fails on Arch Linux with sdl2-compat 2.30.50-1 and sdl3 3.2.0-1 and YCbCr textures).
1 parent a525f47 commit a15c14f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/video_display/sdl2.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
#include <assert.h> // for assert
5555
#include <ctype.h> // for toupper
56+
#include <inttypes.h> // for PRIu8
5657
#include <math.h> // for sqrt
5758
#include <pthread.h> // for pthread_mutex_unlock, pthread_mutex_lock
5859
#include <stdbool.h> // for true, bool, false
@@ -149,7 +150,15 @@ static const struct {
149150
{'q', "quit"},
150151
};
151152

152-
#define SDL_CHECK(cmd) do { int ret = cmd; if (ret < 0) { log_msg(LOG_LEVEL_ERROR, MOD_NAME "Error (%s): %s\n", #cmd, SDL_GetError());} } while(0)
153+
#define SDL_CHECK(cmd, ...) \
154+
do { \
155+
int ret = cmd; \
156+
if (ret < 0) { \
157+
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Error (%s): %s\n", \
158+
#cmd, SDL_GetError()); \
159+
__VA_ARGS__; \
160+
} \
161+
} while (0)
153162

154163
static void display_frame(struct state_sdl2 *s, struct video_frame *frame)
155164
{
@@ -475,7 +484,10 @@ static bool recreate_textures(struct state_sdl2 *s, struct video_desc desc) {
475484
}
476485
struct video_frame *f = vf_alloc_desc(desc);
477486
f->callbacks.dispose_udata = (void *) texture;
478-
SDL_CHECK(SDL_LockTexture(texture, NULL, (void **) &f->tiles[0].data, &s->texture_pitch));
487+
SDL_CHECK(SDL_LockTexture(texture, NULL,
488+
(void **) &f->tiles[0].data,
489+
&s->texture_pitch),
490+
return false);
479491
f->tiles[0].data_len = desc.height * s->texture_pitch;
480492
f->callbacks.data_deleter = vf_sdl_texture_data_deleter;
481493
simple_linked_list_append(s->free_frame_queue, f);

0 commit comments

Comments
 (0)