From 5f57d4775f1ef692eb8dfe6d2f82cd959038db4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 29 Jun 2020 22:47:34 +0200 Subject: [PATCH] Add some excessive null checks to GameScreen::render(), might fix the crash seen in #13057 --- Core/ELF/ParamSFO.h | 24 +++++++---------------- UI/GameScreen.cpp | 47 +++++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Core/ELF/ParamSFO.h b/Core/ELF/ParamSFO.h index 940280bac32f..dca5d1b23e99 100644 --- a/Core/ELF/ParamSFO.h +++ b/Core/ELF/ParamSFO.h @@ -67,28 +67,18 @@ class ParamSFOData class ValueData { public: - ValueType type; - int max_size; + ValueType type = VT_INT; + int max_size = 0; std::string s_value; - int i_value; + int i_value = 0; - u8* u_value; - unsigned int u_size; + u8* u_value = nullptr; + unsigned int u_size = 0; void SetData(const u8* data, int size); - ValueData() - { - u_value = 0; - u_size = 0; - type = VT_INT; - max_size = 0; - i_value = 0; - } - - ~ValueData() - { - if(u_value) + ~ValueData() { + if (u_value) delete[] u_value; } }; diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index f584f45faa87..1c900beecdd1 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -47,8 +47,9 @@ GameScreen::~GameScreen() { void GameScreen::CreateViews() { std::shared_ptr info = g_gameInfoCache->GetInfo(NULL, gamePath_, GAMEINFO_WANTBG | GAMEINFO_WANTSIZE); - if (info && !info->id.empty()) + if (info && !info->id.empty()) { saveDirs = info->GetSaveDataDirectories(); // Get's very heavy, let's not do it in update() + } auto di = GetI18NCategory("Dialog"); auto ga = GetI18NCategory("Game"); @@ -119,9 +120,7 @@ void GameScreen::CreateViews() { rightColumnItems->Add(btnDeleteSaveData_)->OnClick.Handle(this, &GameScreen::OnDeleteSaveData); btnDeleteSaveData_->SetVisibility(V_GONE); - if (info && !info->pending) { - otherChoices_.clear(); - } + otherChoices_.clear(); rightColumnItems->Add(AddOtherChoice(new Choice(ga->T("Delete Game"))))->OnClick.Handle(this, &GameScreen::OnDeleteGame); if (host->CanCreateShortcut()) { @@ -200,29 +199,35 @@ void GameScreen::render() { if (info->gameSize) { char temp[256]; - snprintf(temp, sizeof(temp), "%s: %1.1f %s", ga->T("Game"), (float) (info->gameSize) / 1024.f / 1024.f, ga->T("MB")); - tvGameSize_->SetText(temp); - snprintf(temp, sizeof(temp), "%s: %1.2f %s", ga->T("SaveData"), (float) (info->saveDataSize) / 1024.f / 1024.f, ga->T("MB")); - tvSaveDataSize_->SetText(temp); - if (info->installDataSize > 0) { + if (tvGameSize_) { + snprintf(temp, sizeof(temp), "%s: %1.1f %s", ga->T("Game"), (float)(info->gameSize) / 1024.f / 1024.f, ga->T("MB")); + tvGameSize_->SetText(temp); + } + if (tvSaveDataSize_) { + snprintf(temp, sizeof(temp), "%s: %1.2f %s", ga->T("SaveData"), (float)(info->saveDataSize) / 1024.f / 1024.f, ga->T("MB")); + tvSaveDataSize_->SetText(temp); + } + if (info->installDataSize > 0 && tvInstallDataSize_) { snprintf(temp, sizeof(temp), "%s: %1.2f %s", ga->T("InstallData"), (float) (info->installDataSize) / 1024.f / 1024.f, ga->T("MB")); tvInstallDataSize_->SetText(temp); tvInstallDataSize_->SetVisibility(UI::V_VISIBLE); } } - if (info->region >= 0 && info->region < GAMEREGION_MAX && info->region != GAMEREGION_OTHER) { - static const char *regionNames[GAMEREGION_MAX] = { - "Japan", - "USA", - "Europe", - "Hong Kong", - "Asia", - "Korea" - }; - tvRegion_->SetText(ga->T(regionNames[info->region])); - } else if (info->region > GAMEREGION_MAX){ - tvRegion_->SetText(ga->T("Homebrew")); + if (tvRegion_) { + if (info->region >= 0 && info->region < GAMEREGION_MAX && info->region != GAMEREGION_OTHER) { + static const char *regionNames[GAMEREGION_MAX] = { + "Japan", + "USA", + "Europe", + "Hong Kong", + "Asia", + "Korea" + }; + tvRegion_->SetText(ga->T(regionNames[info->region])); + } else if (info->region > GAMEREGION_MAX) { + tvRegion_->SetText(ga->T("Homebrew")); + } } if (!info->id.empty()) {