Fixed a memory corruption bug in the List's render function.
This commit is contained in:
@@ -18,6 +18,7 @@ typedef struct {
|
||||
|
||||
TextureFontCache* CreateTextureFontCache();
|
||||
TextureDetails* AddTextureToCache(SDL_Texture* texture, unsigned short fontSize, SDL_Rect textSize, TextureFontCache* cache);
|
||||
void UpdateTextureDetails(SDL_Texture* texture, unsigned short fontSize, SDL_Rect textSize, int index, TextureFontCache* cache);
|
||||
TextureDetails* GetTextureFromCache(TextureFontCache* cache, unsigned int index);
|
||||
void FreeTextureDetails(TextureDetails* details);
|
||||
|
||||
|
||||
+3
-2
@@ -45,13 +45,14 @@ void RenderList(SDL_Renderer* renderer, SDL_FPoint motion, TTF_Font* font, unsig
|
||||
TTF_SizeUTF8(font, "List (Array)", &textSize.w, &textSize.h);
|
||||
SDL_Surface* surface = TTF_RenderText_Shaded(font, "List (Array)", (SDL_Color){255, 255, 255, 0}, (SDL_Color){0, 0, 0, 0});
|
||||
|
||||
if (!details) FreeTextureDetails(details);
|
||||
//if (!details) FreeTextureDetails(details);
|
||||
|
||||
SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
details = AddTextureToCache(tex, fontSize, textSize, list->TextureCache);
|
||||
if (details) UpdateTextureDetails(tex, fontSize, textSize, 0, list->TextureCache);
|
||||
else details = AddTextureToCache(tex, fontSize, textSize, list->TextureCache);
|
||||
}
|
||||
|
||||
SDL_FRect size;
|
||||
|
||||
@@ -186,6 +186,7 @@ void HandleInput(void) {
|
||||
Exit = 1;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (event.button.button == SDL_BUTTON_RIGHT) Exit = 1;
|
||||
MouseDown = 1;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
|
||||
@@ -45,6 +45,18 @@ TextureDetails* AddTextureToCache(SDL_Texture* texture, unsigned short fontSize,
|
||||
return cache->Textures[cache->Size - 1];
|
||||
}
|
||||
|
||||
void UpdateTextureDetails(SDL_Texture* texture, unsigned short fontSize, SDL_Rect textSize, int index, TextureFontCache* cache) {
|
||||
if (index >= cache->Size) return;
|
||||
|
||||
TextureDetails* details = cache->Textures[index];
|
||||
|
||||
SDL_DestroyTexture(details->Texture);
|
||||
|
||||
details->Texture = texture;
|
||||
details->FontSize = fontSize;
|
||||
details->TextSize = textSize;
|
||||
}
|
||||
|
||||
void FreeTextureDetails(TextureDetails* details) {
|
||||
if (!details) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user