Add some excessive null checks to GameScreen::render(), might fix the crash seen in #13057

This commit is contained in:
Henrik Rydgård 2020-06-29 22:47:34 +02:00
parent 4569ca60f1
commit 5f57d4775f
2 changed files with 33 additions and 38 deletions

View File

@ -67,28 +67,18 @@ private:
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;
}
};

View File

@ -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");
@ -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()) {