missing textures: fix double free

This commit is contained in:
veclavtalica 2025-01-13 18:09:06 +03:00
parent 3052bb693a
commit 87ae1a7312

View File

@ -68,12 +68,11 @@ static SDL_Surface *gen_missing_texture_surface(void) {
} }
/* same data is reused after being allocated/generated once */ /* same data is reused after being allocated/generated once */
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(missing_texture_data, 64, 64, SDL_Surface *missing_texture_surface = SDL_CreateRGBSurfaceFrom(missing_texture_data, 64, 64,
3 * 8, 3 * 8,
64 * 3, 64 * 3,
rmask, gmask, bmask, 0); rmask, gmask, bmask, 0);
return missing_texture_surface;
return surface;
} }
@ -328,6 +327,7 @@ void textures_cache_deinit(TextureCache *cache) {
/* free cache hashes */ /* free cache hashes */
for (size_t i = 0; i < shlenu(cache->hash); ++i) { for (size_t i = 0; i < shlenu(cache->hash); ++i) {
if (cache->hash[i].value.data->pixels != missing_texture_data)
stbi_image_free(cache->hash[i].value.data->pixels); stbi_image_free(cache->hash[i].value.data->pixels);
SDL_FreeSurface(cache->hash[i].value.data); SDL_FreeSurface(cache->hash[i].value.data);
} }