Skip to content

Commit

Permalink
Add some excessive null checks to GameScreen::render(), might fix the…
Browse files Browse the repository at this point in the history
… crash seen in #13057
  • Loading branch information
hrydgard committed Jun 29, 2020
1 parent 4569ca6 commit 5f57d47
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
24 changes: 7 additions & 17 deletions Core/ELF/ParamSFO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
47 changes: 26 additions & 21 deletions UI/GameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ GameScreen::~GameScreen() {
void GameScreen::CreateViews() {
std::shared_ptr<GameInfo> 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");
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 5f57d47

Please sign in to comment.