twn_textures: fix freeing of missed texture
This commit is contained in:
parent
35bb26705a
commit
4a41f47a58
@ -73,19 +73,20 @@ static SDL_Surface *gen_missing_texture_surface(void) {
|
|||||||
SDL_LockMutex(textures_load_mutex);
|
SDL_LockMutex(textures_load_mutex);
|
||||||
|
|
||||||
if (!missing_texture_surface) {
|
if (!missing_texture_surface) {
|
||||||
uint8_t *data = SDL_malloc(64 * 64 * 3);
|
int const dim = + TEXTURE_BORDER_REPEAT_SIZE * 2;
|
||||||
for (int y = 0; y < 64; ++y) {
|
uint8_t *data = SDL_malloc(dim * dim * 3);
|
||||||
for (int x = 0; x < 64; ++x) {
|
for (int y = 0; y < dim; ++y) {
|
||||||
|
for (int x = 0; x < dim; ++x) {
|
||||||
/* diagonal stripes, chosen so that asked pixel uvs are corresponding to final output */
|
/* diagonal stripes, chosen so that asked pixel uvs are corresponding to final output */
|
||||||
data[(y * 64 + x) * 3 + 0] = (x / 2 + y / 2) % 2 == 0 ? 175 : 0;
|
data[(y * dim + x) * 3 + 0] = (x / 2 + y / 2) % 2 == 0 ? 175 : 0;
|
||||||
data[(y * 64 + x) * 3 + 1] = (x / 2 + y / 2) % 2 == 0 ? 0 : 0;
|
data[(y * dim + x) * 3 + 1] = (x / 2 + y / 2) % 2 == 0 ? 0 : 0;
|
||||||
data[(y * 64 + x) * 3 + 2] = (x / 2 + y / 2) % 2 == 0 ? 175 : 0;
|
data[(y * dim + x) * 3 + 2] = (x / 2 + y / 2) % 2 == 0 ? 175 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
missing_texture_surface = SDL_CreateRGBSurfaceFrom(data, 64, 64,
|
missing_texture_surface = SDL_CreateRGBSurfaceFrom(data, dim, dim,
|
||||||
3 * 8,
|
3 * 8,
|
||||||
64 * 3,
|
dim * 3,
|
||||||
rmask, gmask, bmask, 0);
|
rmask, gmask, bmask, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,10 +300,8 @@ static stbrp_rect *create_rects_from_cache(TextureCache *cache) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* only put it once */
|
/* only put it once */
|
||||||
if (!missing_texture_used && cache->hash[i].value.data == missing_texture_surface) {
|
if (!missing_texture_used && cache->hash[i].value.data == missing_texture_surface)
|
||||||
missing_texture_used = true;
|
missing_texture_used = true;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SDL_Surface *surface_data = cache->hash[i].value.data;
|
const SDL_Surface *surface_data = cache->hash[i].value.data;
|
||||||
stbrp_rect new_rect = {
|
stbrp_rect new_rect = {
|
||||||
@ -412,12 +411,12 @@ 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) {
|
||||||
/* TODO: better to have field that stores the source of memory directly, ugh */
|
/* TODO: better to have field that stores the source of memory directly, ugh */
|
||||||
if (cache->hash[i].value.srcrect.w < 2048 && cache->hash[i].value.srcrect.h < 2048)
|
if (missing_texture_surface != NULL && cache->hash[i].value.data->pixels == missing_texture_surface->pixels)
|
||||||
(void)0; /* do nothing, memory owned by surface */
|
|
||||||
else if (missing_texture_surface == NULL || cache->hash[i].value.data->pixels != missing_texture_surface->pixels)
|
|
||||||
stbi_image_free(cache->hash[i].value.data->pixels);
|
|
||||||
else
|
|
||||||
SDL_free(cache->hash[i].value.data->pixels);
|
SDL_free(cache->hash[i].value.data->pixels);
|
||||||
|
else if (cache->hash[i].value.srcrect.w < 2048 && cache->hash[i].value.srcrect.h < 2048)
|
||||||
|
(void)0; /* do nothing, memory owned by surface */
|
||||||
|
else
|
||||||
|
stbi_image_free(cache->hash[i].value.data->pixels);
|
||||||
SDL_FreeSurface(cache->hash[i].value.data);
|
SDL_FreeSurface(cache->hash[i].value.data);
|
||||||
}
|
}
|
||||||
shfree(cache->hash);
|
shfree(cache->hash);
|
||||||
|
Loading…
Reference in New Issue
Block a user