summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-06 19:37:06 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-06 19:37:06 (EDT)
commit67ec83b3a6a59567421ebec8bdbc985645fbba90 (patch)
tree7d32da0362d3ce713b02a98182a8c4ac3bea6498 /src/tk
parent6d43b932c0af090dc4cb89ce0e494c4cfd3c4f7d (diff)
downloadmazefight-67ec83b3a6a59567421ebec8bdbc985645fbba90.zip
mazefight-67ec83b3a6a59567421ebec8bdbc985645fbba90.tar.gz
mazefight-67ec83b3a6a59567421ebec8bdbc985645fbba90.tar.bz2
tk: Handle zero-width text rendering
Fixes: ERROR: Couldn't create surface: Text has zero width
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/text.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/tk/text.c b/src/tk/text.c
index 1cbeb50..5d61682 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -193,7 +193,8 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
SDL_Rect rect;
int cur_x;
- if (t->texture == NULL && _mftk_text_render_val(t, renderer) < 0) {
+ if (t->val[0] != '\0' && t->texture == NULL &&
+ _mftk_text_render_val(t, renderer) < 0) {
return -1;
}
@@ -206,9 +207,14 @@ _mftk_text_render(struct mftk_widget *w, SDL_Renderer *renderer, int x, int y)
t->curval[t->cur] = '\0';
TTF_SizeUTF8(t->font, t->curval, &cur_x, NULL);
- if (SDL_RenderCopy(renderer, t->texture, NULL, &rect) < 0 ||
- SDL_SetRenderDrawColor(renderer,
- t->color->r, t->color->g,
+ if (t->val[0] != '\0' &&
+ SDL_RenderCopy(renderer, t->texture, NULL, &rect) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Couldn't render widget: %s",
+ SDL_GetError());
+ return -1;
+ }
+ if (SDL_SetRenderDrawColor(renderer, t->color->r, t->color->g,
t->color->b, t->color->a) < 0 ||
SDL_RenderDrawLine(renderer,
x, y + w->h, x + w->w, y + w->h) < 0) {