Skip to content

Fix bugs in savedata manager #20170

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

Merged
merged 3 commits into from
Mar 27, 2025
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
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ static std::string surface_transforms_to_string(VkSurfaceTransformFlagsKHR trans
}

bool VulkanContext::InitSwapchain() {
_assert_(physical_device_ >= 0 && physical_device_ < physical_devices_.size());
_assert_(physical_device_ >= 0 && physical_device_ < (int)physical_devices_.size());
if (!surface_) {
ERROR_LOG(Log::G3D, "VK: No surface, can't create swapchain");
return false;
Expand Down
4 changes: 2 additions & 2 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ VKRPipelineLayout *VulkanRenderManager::CreatePipelineLayout(BindingType *bindin
memcpy(layout->bindingTypes, bindingTypes, sizeof(BindingType) * bindingTypesCount);

VkDescriptorSetLayoutBinding bindings[VKRPipelineLayout::MAX_DESC_SET_BINDINGS];
for (int i = 0; i < bindingTypesCount; i++) {
for (int i = 0; i < (int)bindingTypesCount; i++) {
bindings[i].binding = i;
bindings[i].descriptorCount = 1;
bindings[i].pImmutableSamplers = nullptr;
Expand Down Expand Up @@ -1869,7 +1869,7 @@ void VKRPipelineLayout::FlushDescSets(VulkanContext *vulkan, int frame, QueuePro
void VulkanRenderManager::SanityCheckPassesOnAdd() {
#if _DEBUG
// Check that we don't have any previous passes that write to the backbuffer, that must ALWAYS be the last one.
for (int i = 0; i < steps_.size(); i++) {
for (int i = 0; i < (int)steps_.size(); i++) {
if (steps_[i]->stepType == VKRStepType::RENDER) {
_dbg_assert_msg_(steps_[i]->render.framebuffer != nullptr, "Adding second backbuffer pass? Not good!");
}
Expand Down
4 changes: 2 additions & 2 deletions Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class VKPipeline : public Pipeline {
}

void SetDynamicUniformData(const void *data, size_t size) {
_dbg_assert_(size <= uboSize_);
_dbg_assert_((int)size <= uboSize_);
memcpy(ubo_, data, size);
}

Expand Down Expand Up @@ -822,7 +822,7 @@ bool VKTexture::Create(VkCommandBuffer cmd, VulkanBarrierBatch *postBarriers, Vu
if (desc.initData.size()) {
UpdateInternal(cmd, pushBuffer, desc.initData.data(), desc.initDataCallback, (int)desc.initData.size());
// Generate the rest of the mips automatically.
if (desc.initData.size() < mipLevels_) {
if ((int)desc.initData.size() < mipLevels_) {
vkTex_->GenerateMips(cmd, (int)desc.initData.size(), false);
layout = VK_IMAGE_LAYOUT_GENERAL;
}
Expand Down
12 changes: 12 additions & 0 deletions Common/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction
// First, remove any chars not in A-Za-z0-9_-. This will effectively get rid of any Unicode char, emojis etc too.
std::string sanitized;
sanitized.reserve(input.size());
bool lastWasLineBreak = false;
for (auto c : input) {
switch (restriction) {
case StringRestriction::None:
Expand All @@ -125,6 +126,17 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction
sanitized.push_back(c);
}
break;
case StringRestriction::NoLineBreaksOrSpecials:
if (c >= 32) {
sanitized.push_back(c);
lastWasLineBreak = false;
} else if (c == 10 || c == 13) {
// Collapse line breaks/feeds to single spaces.
if (!lastWasLineBreak) {
sanitized.push_back(' ');
}
lastWasLineBreak = true;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Common/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ bool containsNoCase(std::string_view haystack, std::string_view needle);
enum class StringRestriction {
None,
AlphaNumDashUnderscore, // Used for infrastructure usernames
NoLineBreaksOrSpecials, // Used for savedata UI. Removes line breaks, backslashes and similar.
};

std::string SanitizeString(std::string_view username, StringRestriction restriction, int minLength, int maxLength);
Expand Down
9 changes: 7 additions & 2 deletions UI/SavedataScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ void SavedataScreen::CreateSavedataTab(UI::ViewGroup *savedata) {
if (!searchFilter_.empty())
dataBrowser_->SetSearchFilter(searchFilter_);
dataBrowser_->OnChoice.Handle(this, &SavedataScreen::OnSavedataButtonClick);

}

void SavedataScreen::CreateSavestateTab(UI::ViewGroup *savestate) {
Expand Down Expand Up @@ -699,7 +698,10 @@ UI::EventReturn SavedataScreen::OnSavedataButtonClick(UI::EventParams &e) {
if (!ginfo->Ready(GameInfoFlags::PARAM_SFO)) {
return UI::EVENT_DONE;
}
SavedataPopupScreen *popupScreen = new SavedataPopupScreen(gamePath_, Path(e.s), ginfo->GetTitle());

// Sanitize the title.
std::string title = SanitizeString(ginfo->GetTitle(), StringRestriction::NoLineBreaksOrSpecials, 0, 200);
SavedataPopupScreen *popupScreen = new SavedataPopupScreen(gamePath_, Path(e.s), title);
if (e.v) {
popupScreen->SetPopupOrigin(e.v);
}
Expand All @@ -716,7 +718,10 @@ void SavedataScreen::dialogFinished(const Screen *dialog, DialogResult result) {

void SavedataScreen::sendMessage(UIMessage message, const char *value) {
UIDialogScreenWithGameBackground::sendMessage(message, value);

if (message == UIMessage::SAVEDATA_SEARCH) {
EnsureTabs();

searchFilter_ = value;
dataBrowser_->SetSearchFilter(searchFilter_);
stateBrowser_->SetSearchFilter(searchFilter_);
Expand Down
4 changes: 4 additions & 0 deletions UI/TabbedDialogScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ void TabbedUIDialogScreenWithGameBackground::RecreateViews() {
UIScreen::RecreateViews();
}

void TabbedUIDialogScreenWithGameBackground::EnsureTabs() {
tabHolder_->EnsureAllCreated();
}

void TabbedUIDialogScreenWithGameBackground::ApplySearchFilter() {
using namespace UI;
auto se = GetI18NCategory(I18NCat::SEARCH);
Expand Down
1 change: 1 addition & 0 deletions UI/TabbedDialogScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TabbedUIDialogScreenWithGameBackground : public UIDialogScreenWithGameBack
virtual void CreateTabs() = 0;
virtual void CreateExtraButtons(UI::LinearLayout *verticalLayout, int margins) {}
virtual bool ShowSearchControls() const { return true; }
virtual void EnsureTabs();

void RecreateViews() override;
void sendMessage(UIMessage message, const char *value) override;
Expand Down
Loading