Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some excessive null checks to GameScreen::render() #13076

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, maybe this was it. If otherChoices were added before somehow, and the cache was cleared (can an app switch do that?), then we might have stale but deleted pointers there.

-[Unknown]


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