diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-03-24 10:02:51 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-03-24 10:03:26 (EDT) |
commit | f1de5e0a816846e82aabc46639f1b59dec09638b (patch) | |
tree | 746004f21e2e2d554fac49ddcb13a2ab65a3a348 | |
parent | 5ae17e4d78aefc97f22dbafddb054efe28c2f69d (diff) | |
download | dodge-balls-f1de5e0a816846e82aabc46639f1b59dec09638b.zip dodge-balls-f1de5e0a816846e82aabc46639f1b59dec09638b.tar.gz dodge-balls-f1de5e0a816846e82aabc46639f1b59dec09638b.tar.bz2 |
map: Clear texture and handle render copy errors
-rw-r--r-- | src/map.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -505,7 +505,7 @@ _db_tmx_map_start(void *pv, const char *name, const char **attr) } } -static void +static int _db_map_render_layer(struct db_map *map, struct db_map_layer *layer, SDL_Renderer *renderer, SDL_Texture *texture) { @@ -553,8 +553,12 @@ _db_map_render_layer(struct db_map *map, struct db_map_layer *layer, tile_rect.w, tile_rect.h, tile_rect.x, tile_rect.y, layer_rect.x, layer_rect.y); - SDL_RenderCopy(renderer, texture, - &tile_rect, &layer_rect); + if (SDL_RenderCopy(renderer, texture, + &tile_rect, &layer_rect) != 0) { + db_err("Failed to copy texture (%s)", + SDL_GetError()); + return -1; + } tile_found = SDL_TRUE; break; } @@ -563,6 +567,8 @@ _db_map_render_layer(struct db_map *map, struct db_map_layer *layer, db_warn("Tile with gid 0x%8.8x not found", gid); } } + + return 0; } SDL_Texture * @@ -582,9 +588,15 @@ db_map_render(struct db_map *map, SDL_Renderer *renderer) SDL_TEXTUREACCESS_TARGET, map->w, map->h); old_target = SDL_GetRenderTarget(renderer); SDL_SetRenderTarget(renderer, texture); + if (SDL_RenderClear(renderer) != 0) { + db_err("Failed to clear texture (%s)", SDL_GetError()); + return NULL; + } for (layer = map->layer_head; layer != NULL; layer = layer->next) { - _db_map_render_layer(map, layer, renderer, texture); + if (_db_map_render_layer(map, layer, renderer, texture) != 0) { + return NULL; + } } SDL_SetRenderTarget(renderer, old_target); |