fix missing texture over NULL

This commit is contained in:
veclavtalica 2025-02-07 12:47:40 +03:00
parent 7040d6f218
commit 990135105a

View File

@ -79,6 +79,9 @@ static SDL_Surface *gen_missing_texture_surface(void) {
SDL_Surface *textures_load_surface(const char *path) { SDL_Surface *textures_load_surface(const char *path) {
if (SDL_strncmp(path, "!", 1) == 0)
goto GET_MISSING_TEXTURE;
SDL_RWops *handle = PHYSFSRWOPS_openRead(path); SDL_RWops *handle = PHYSFSRWOPS_openRead(path);
if (handle == NULL) if (handle == NULL)
goto ERR_CANNOT_OPEN_FILE; goto ERR_CANNOT_OPEN_FILE;
@ -133,6 +136,7 @@ ERR_CANNOT_READ_IMAGE:
ERR_CANNOT_OPEN_FILE: ERR_CANNOT_OPEN_FILE:
/* something didn't worked out, use a stub texture */ /* something didn't worked out, use a stub texture */
log_warn("Cannot open image: %s, using a stub", path); log_warn("Cannot open image: %s, using a stub", path);
GET_MISSING_TEXTURE:
return gen_missing_texture_surface(); return gen_missing_texture_surface();
} }
@ -465,7 +469,7 @@ void textures_update_atlas(TextureCache *cache) {
TextureKey textures_get_key(TextureCache *cache, const char *path) { TextureKey textures_get_key(TextureCache *cache, const char *path) {
/* to prevent hashing errors */ /* to prevent hashing errors */
if (!path) path = ""; if (!path) path = "!";
/* hash tables are assumed to be stable, so we just return indices */ /* hash tables are assumed to be stable, so we just return indices */
const ptrdiff_t texture = shgeti(cache->hash, path); const ptrdiff_t texture = shgeti(cache->hash, path);