From 39826bab0cd0d1075c1ec23b1341c06f854763a8 Mon Sep 17 00:00:00 2001 From: Aemiii91 <44569252+Aemiii91@users.noreply.github.com> Date: Sun, 23 Jun 2024 21:48:06 +0200 Subject: [PATCH] Fix GS and Tweaks crashing when using AdobeBlank --- src/common/theme/render/battery.h | 14 ++++++++++---- src/common/theme/render/footer.h | 22 ++++++++++++++-------- src/common/theme/render/textbox.h | 13 +++++++++---- src/gameSwitcher/gameSwitcher.c | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/common/theme/render/battery.h b/src/common/theme/render/battery.h index 22bec69ef..397dc6d77 100644 --- a/src/common/theme/render/battery.h +++ b/src/common/theme/render/battery.h @@ -38,13 +38,20 @@ SDL_Surface *theme_batterySurfaceWithBg(int percentage, SDL_Surface *background) // Battery percentage text char buffer[5]; sprintf(buffer, "%d%%", percentage); - SDL_Surface *text = TTF_RenderUTF8_Blended(font, buffer, style->color); - SDL_SetAlpha(text, 0, SDL_ALPHA_TRANSPARENT); /* important */ // Battery icon ThemeImages icon_request = _getBatteryRequest(percentage); SDL_Surface *icon = resource_getSurface(icon_request); + SDL_Surface *image = NULL; + SDL_Surface *text = TTF_RenderUTF8_Blended(font, buffer, style->color); + + if (!text) { + text = SDL_CreateRGBSurface(0, 1, 1, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + } + + SDL_SetAlpha(text, 0, SDL_ALPHA_TRANSPARENT); /* important */ + if (icon->w > 640) visible = false; @@ -70,7 +77,7 @@ SDL_Surface *theme_batterySurfaceWithBg(int percentage, SDL_Surface *background) if (img_height < 48) img_height = 48; - SDL_Surface *image = SDL_CreateRGBSurface(0, img_width, img_height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + image = SDL_CreateRGBSurface(0, img_width, img_height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); SDL_Rect rect_icon = {0, (img_height - icon->h) / 2}; SDL_Rect rect_text = {0, (img_height - text->h) / 2 + offsetY}; @@ -109,7 +116,6 @@ SDL_Surface *theme_batterySurfaceWithBg(int percentage, SDL_Surface *background) icon = SDL_ConvertSurface(icon, image->format, 0); SDL_SetAlpha(icon, 0, SDL_ALPHA_TRANSPARENT); /* important */ - SDL_BlitSurface(icon, NULL, image, &rect_icon); if (visible) diff --git a/src/common/theme/render/footer.h b/src/common/theme/render/footer.h index b7903040e..ba0b17b0b 100644 --- a/src/common/theme/render/footer.h +++ b/src/common/theme/render/footer.h @@ -97,15 +97,21 @@ void theme_renderFooterStatus(SDL_Surface *screen, int current_num, SDL_Surface *total = TTF_RenderUTF8_Blended(font_hint, total_str, theme()->total.color); - SDL_Rect total_rect = {620 - total->w, 449 - total->h / 2}; - SDL_Rect current_rect = {total_rect.x - current->w, 449 - current->h / 2}; - old_status_width = total->w + current->w; - - SDL_BlitSurface(total, NULL, screen, &total_rect); - SDL_BlitSurface(current, NULL, screen, ¤t_rect); + if (total) { + SDL_Rect current_rect = {0, 0}; + SDL_Rect total_rect = {620 - total->w, 449 - total->h / 2}; + + SDL_BlitSurface(total, NULL, screen, &total_rect); + if (current) { + current_rect.x = total_rect.x - current->w; + current_rect.y = 449 - current->h / 2; + old_status_width = total->w + current->w; + SDL_BlitSurface(current, NULL, screen, ¤t_rect); + SDL_FreeSurface(current); + } - SDL_FreeSurface(current); - SDL_FreeSurface(total); + SDL_FreeSurface(total); + } } void theme_renderListFooter(SDL_Surface *screen, int current_num, int total_num, diff --git a/src/common/theme/render/textbox.h b/src/common/theme/render/textbox.h index bd6655cc5..704cfab6c 100644 --- a/src/common/theme/render/textbox.h +++ b/src/common/theme/render/textbox.h @@ -24,10 +24,12 @@ SDL_Surface *theme_textboxSurface(const char *message, TTF_Font *font, token = strtok(s, delim); while (token != NULL) { lines[line_count] = TTF_RenderUTF8_Blended(font, token, fg); - SDL_SetAlpha(lines[line_count], 0, 0); /* important */ - if (lines[line_count]->w > line_width) - line_width = lines[line_count]->w; - line_count++; + if (lines[line_count]) { + SDL_SetAlpha(lines[line_count], 0, 0); /* important */ + if (lines[line_count]->w > line_width) + line_width = lines[line_count]->w; + line_count++; + } token = strtok(NULL, delim); } @@ -40,6 +42,9 @@ SDL_Surface *theme_textboxSurface(const char *message, TTF_Font *font, int i; for (i = 0; i < line_count; i++) { + if (!lines[i]) { + continue; + } if (align == ALIGN_CENTER) line_rect.x = (line_width - lines[i]->w) / 2; else if (align == ALIGN_RIGHT) diff --git a/src/gameSwitcher/gameSwitcher.c b/src/gameSwitcher/gameSwitcher.c index b6917df86..0bd2fb73d 100644 --- a/src/gameSwitcher/gameSwitcher.c +++ b/src/gameSwitcher/gameSwitcher.c @@ -135,7 +135,7 @@ SDL_Surface *loadRomScreen(int index) // Show artwork if (!exists(currPicture)) - sprintf(currPicture, game->romImagePath); + sprintf(currPicture, game->romImagePath); if (exists(currPicture)) { strcpy(game->romImagePath, currPicture);