Skip to content

Commit

Permalink
Merge pull request #19507 from hrydgard/misc-fixes-again
Browse files Browse the repository at this point in the history
Prevent soft-locking the emulator on bad PBP files
  • Loading branch information
hrydgard authored Oct 3, 2024
2 parents 355ec02 + 6d3849b commit 16d97aa
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ bool SavedataParam::Delete(SceUtilitySavedataParam* param, int saveId) {

std::string dirPath = GetSaveFilePath(param, GetSaveDir(saveId));
if (dirPath.size() == 0) {
ERROR_LOG(Log::sceUtility, "GetSaveFilePath (%.*s) returned empty - cannot delete save directory. Might already be deleted?", sizeof(param->gameName), param->gameName);
ERROR_LOG(Log::sceUtility, "GetSaveFilePath (%.*s) returned empty - cannot delete save directory. Might already be deleted?", (int)sizeof(param->gameName), param->gameName);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRRegCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ constexpr int TOTAL_MAPPABLE_IRREGS = 256;
// Arbitrary - increase if your backend has more.
constexpr int TOTAL_POSSIBLE_NATIVEREGS = 128;

typedef int8_t IRNativeReg;
typedef int8_t IRNativeReg; // invalid value is -1

constexpr IRReg IRREG_INVALID = 255;

Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/x86/X64IRRegCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ X64Reg X64IRRegCache::GetAndLockTempFPR() {

void X64IRRegCache::ReserveAndLockXGPR(Gen::X64Reg r) {
IRNativeReg nreg = GPRToNativeReg(r);
if (nr[nreg].mipsReg != -1)
if (nr[nreg].mipsReg != IRREG_INVALID)
FlushNativeReg(nreg);
nr[r].tempLockIRIndex = irIndex_;
}
Expand Down
38 changes: 25 additions & 13 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ static UI::AnchorLayoutParams *AnchorInCorner(const Bounds &bounds, int corner,
void EmuScreen::CreateViews() {
using namespace UI;

auto di = GetI18NCategory(I18NCat::DIALOG);
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
auto sc = GetI18NCategory(I18NCat::SCREEN);

Expand All @@ -1043,9 +1044,21 @@ void EmuScreen::CreateViews() {
resumeButton_->SetVisibility(V_GONE);

resetButton_ = buttons->Add(new Button(dev->T("Reset")));
resetButton_->OnClick.Handle(this, &EmuScreen::OnReset);
resetButton_->OnClick.Add([](UI::EventParams &) {
if (coreState == CoreState::CORE_RUNTIME_ERROR) {
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
}
return UI::EVENT_DONE;
});
resetButton_->SetVisibility(V_GONE);

backButton_ = buttons->Add(new Button(dev->T("Back")));
backButton_->OnClick.Add([this](UI::EventParams &) {
this->pauseTrigger_ = true;
return UI::EVENT_DONE;
});
backButton_->SetVisibility(V_GONE);

cardboardDisableButton_ = root_->Add(new Button(sc->T("Cardboard VR OFF"), new AnchorLayoutParams(bounds.centerX(), NONE, NONE, 30, true)));
cardboardDisableButton_->OnClick.Handle(this, &EmuScreen::OnDisableCardboard);
cardboardDisableButton_->SetVisibility(V_GONE);
Expand Down Expand Up @@ -1166,19 +1179,13 @@ UI::EventReturn EmuScreen::OnResume(UI::EventParams &params) {
return UI::EVENT_DONE;
}

UI::EventReturn EmuScreen::OnReset(UI::EventParams &params) {
if (coreState == CoreState::CORE_RUNTIME_ERROR) {
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
}
return UI::EVENT_DONE;
}

void EmuScreen::update() {
using namespace UI;

UIScreen::update();
resumeButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR && Memory::MemFault_MayBeResumable() ? V_VISIBLE : V_GONE);
resetButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR ? V_VISIBLE : V_GONE);
backButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR ? V_VISIBLE : V_GONE);

if (chatButton_ && chatMenu_) {
if (chatMenu_->GetVisibility() != V_GONE) {
Expand Down Expand Up @@ -1224,18 +1231,18 @@ void EmuScreen::update() {
return;
}

if (pauseTrigger_) {
pauseTrigger_ = false;
screenManager()->push(new GamePauseScreen(gamePath_));
}

if (invalid_)
return;

double now = time_now_d();

controlMapper_.Update(now);

if (pauseTrigger_) {
pauseTrigger_ = false;
screenManager()->push(new GamePauseScreen(gamePath_));
}

if (saveStatePreview_ && !bootPending_) {
int currentSlot = SaveState::GetCurrentSlot();
if (saveStateSlot_ != currentSlot) {
Expand Down Expand Up @@ -1297,6 +1304,11 @@ ScreenRenderRole EmuScreen::renderRole(bool isTop) const {
return true;
return false;
}

if (invalid_) {
return false;
}

return true;
};

Expand Down
2 changes: 1 addition & 1 deletion UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class EmuScreen : public UIScreen {
UI::EventReturn OnDisableCardboard(UI::EventParams &params);
UI::EventReturn OnChat(UI::EventParams &params);
UI::EventReturn OnResume(UI::EventParams &params);
UI::EventReturn OnReset(UI::EventParams &params);

void bootGame(const Path &filename);
bool bootAllowStorage(const Path &filename);
Expand Down Expand Up @@ -114,6 +113,7 @@ class EmuScreen : public UIScreen {
UI::TextView *loadingTextView_ = nullptr;
UI::Button *resumeButton_ = nullptr;
UI::Button *resetButton_ = nullptr;
UI::Button *backButton_ = nullptr;
UI::View *chatButton_ = nullptr;
ChatMenu *chatMenu_ = nullptr;

Expand Down
11 changes: 11 additions & 0 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ class GameInfoWorkItem : public Task {
goto handleELF;
}
ERROR_LOG(Log::Loader, "invalid pbp '%s'\n", pbpLoader->GetPath().c_str());
// We can't win here - just mark everything pending as fetched, and let the caller
// handle the missing data.
std::unique_lock<std::mutex> lock(info_->lock);
info_->MarkReadyNoLock(flags_);
return;
}

Expand Down Expand Up @@ -720,10 +724,17 @@ class GameInfoWorkItem : public Task {
// few files.
auto fl = info_->GetFileLoader();
if (!fl) {
// BAD! Can't win here.
ERROR_LOG(Log::Loader, "Failed getting game info for ISO %s", info_->GetFilePath().ToVisualString().c_str());
std::unique_lock<std::mutex> lock(info_->lock);
info_->MarkReadyNoLock(flags_);
return;
}
BlockDevice *bd = constructBlockDevice(info_->GetFileLoader().get());
if (!bd) {
ERROR_LOG(Log::Loader, "Failed constructing block device for ISO %s", info_->GetFilePath().ToVisualString().c_str());
std::unique_lock<std::mutex> lock(info_->lock);
info_->MarkReadyNoLock(flags_);
return;
}
ISOFileSystem umd(&handles, bd);
Expand Down

0 comments on commit 16d97aa

Please sign in to comment.