diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index eec14e46a4..49c284bb4e 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -291,7 +291,7 @@ void CPUInfo::Detect() } } #elif PPSSPP_PLATFORM(WINDOWS) - truncate_cpy(brand_string, GetCPUBrandString().c_str()); + truncate_cpy(brand_string, GetCPUBrandString()); isVFP3 = true; isVFP4 = false; SYSTEM_INFO sysInfo; @@ -319,8 +319,8 @@ void CPUInfo::Detect() bFP = false; bASIMD = false; #else // PPSSPP_PLATFORM(LINUX) - truncate_cpy(cpu_string, GetCPUString().c_str()); - truncate_cpy(brand_string, GetCPUBrandString().c_str()); + truncate_cpy(cpu_string, GetCPUString()); + truncate_cpy(brand_string, GetCPUBrandString()); bSwp = CheckCPUFeature("swp"); bHalf = CheckCPUFeature("half"); diff --git a/Common/Data/Format/IniFile.cpp b/Common/Data/Format/IniFile.cpp index 4982a2c819..349022a5cb 100644 --- a/Common/Data/Format/IniFile.cpp +++ b/Common/Data/Format/IniFile.cpp @@ -300,23 +300,19 @@ void Section::Set(std::string_view key, bool newValue, bool defaultValue) Delete(key); } -void Section::Set(std::string_view key, const std::vector& newValues) -{ +void Section::Set(std::string_view key, const std::vector &newValues) { std::string temp; // Join the strings with , for (const auto &value : newValues) { - temp += value + ","; + temp += value; + temp.push_back(','); } // remove last , - if (temp.length()) - temp.resize(temp.length() - 1); + if (!temp.empty()) + temp.pop_back(); Set(key, temp.c_str()); } -void Section::AddComment(const std::string &comment) { - lines_.emplace_back(ParsedIniLine::CommentOnly("# " + comment)); -} - bool Section::Get(std::string_view key, std::vector *values, const std::vector *defaultValues) const { std::string temp; bool retval = Get(key, &temp, 0); @@ -326,23 +322,8 @@ bool Section::Get(std::string_view key, std::vector *values, const } return false; } - // ignore starting , if any - size_t subStart = temp.find_first_not_of(','); - size_t subEnd; - // split by , - while (subStart != std::string::npos) { - // Find next , - subEnd = temp.find_first_of(',', subStart); - if (subStart != subEnd) { - // take from first char until next , - values->push_back(StripSpaces(temp.substr(subStart, subEnd - subStart))); - } - - // Find the next non , char - subStart = temp.find_first_not_of(',', subEnd); - } - + SplitString(temp, ',', *values, true); return true; } @@ -408,6 +389,10 @@ bool Section::Exists(std::string_view key) const { return false; } +void Section::AddComment(const std::string &comment) { + lines_.emplace_back(ParsedIniLine::CommentOnly("# " + comment)); +} + std::map Section::ToMap() const { std::map outMap; for (auto &line : lines_) { @@ -502,8 +487,7 @@ void IniFile::SortSections() std::sort(sections.begin(), sections.end()); } -bool IniFile::Load(const Path &path) -{ +bool IniFile::Load(const Path &path) { sections.clear(); sections.push_back(std::make_unique
("")); // first section consists of the comments before the first real section @@ -531,15 +515,10 @@ bool IniFile::LoadFromVFS(VFSInterface &vfs, const std::string &filename) { } bool IniFile::Load(std::istream &in) { - // Maximum number of letters in a line - static const int MAX_BYTES = 1024*32; - char *templine = new char[MAX_BYTES]; // avoid using up massive stack space - - while (!(in.eof() || in.fail())) - { - in.getline(templine, MAX_BYTES); - std::string_view line = templine; + std::string linebuf; + while (std::getline(in, linebuf)) { + std::string_view line = StripSpaces(std::string_view(linebuf)); // Remove UTF-8 byte order marks. if (line.substr(0, 3) == "\xEF\xBB\xBF") { line = line.substr(3); @@ -575,7 +554,6 @@ bool IniFile::Load(std::istream &in) { } } - delete[] templine; return true; } diff --git a/Common/GPU/OpenGL/GLFeatures.cpp b/Common/GPU/OpenGL/GLFeatures.cpp index 32e1aba67d..5a603aabe0 100644 --- a/Common/GPU/OpenGL/GLFeatures.cpp +++ b/Common/GPU/OpenGL/GLFeatures.cpp @@ -162,7 +162,7 @@ bool CheckGLExtensions() { const char *cvendor = (char *)glGetString(GL_VENDOR); // TODO: move this stuff to gpu_features.cpp if (cvendor) { - const std::string vendor = StripSpaces(std::string(cvendor)); + const std::string vendor(StripSpaces(cvendor)); if (vendor == "NVIDIA Corporation" || vendor == "Nouveau" || vendor == "nouveau") { diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 577f44bfa1..99296ea8a8 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -833,7 +833,7 @@ void VulkanRenderManager::ReportBadStateForDraw() { if (curRenderStep_ && curRenderStep_->stepType != VKRStepType::RENDER) { cause1 = "Not a render step: "; std::string str = VulkanQueueRunner::StepToString(vulkan_, *curRenderStep_); - truncate_cpy(cause2, str.c_str()); + truncate_cpy(cause2, str); } ERROR_LOG_REPORT_ONCE(baddraw, Log::G3D, "Can't draw: %s%s. Step count: %d", cause1, cause2, (int)steps_.size()); } diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 1e54544626..e17565f2c0 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -226,8 +226,10 @@ Client::~Client() { // Ignores line folding (deprecated), but respects field combining. // Don't use for Set-Cookie, which is a special header per RFC 7230. -bool GetHeaderValue(const std::vector &responseHeaders, const std::string &header, std::string *value) { - std::string search = header + ":"; +bool GetHeaderValue(const std::vector &responseHeaders, std::string_view header, std::string *value) { + std::string search(header); + search.push_back(':'); + bool found = false; value->clear(); @@ -242,7 +244,7 @@ bool GetHeaderValue(const std::vector &responseHeaders, const std:: if (!found) *value = stripped.substr(value_pos); else - *value += "," + stripped.substr(value_pos); + *value += "," + std::string(stripped.substr(value_pos)); found = true; } } diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index bd21c9b0fe..c8a147db56 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -47,7 +47,7 @@ private: namespace http { -bool GetHeaderValue(const std::vector &responseHeaders, const std::string &header, std::string *value); +bool GetHeaderValue(const std::vector &responseHeaders, std::string_view header, std::string *value); class RequestParams { public: diff --git a/Common/RiscVCPUDetect.cpp b/Common/RiscVCPUDetect.cpp index cd3f3c3386..53670c1f1e 100644 --- a/Common/RiscVCPUDetect.cpp +++ b/Common/RiscVCPUDetect.cpp @@ -194,7 +194,7 @@ void CPUInfo::Detect() if (logical_cpu_count <= 0) logical_cpu_count = 1; - truncate_cpy(cpu_string, parser.ISAString().c_str()); + truncate_cpy(cpu_string, parser.ISAString()); // A number of CPUs support a limited set of bitmanip. It's not all U74, so we use SOC for now... if (parser.FirmwareMatchesCompatible("starfive,jh7110")) { diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 8ea4e4d02c..3f119d3ac1 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -16,7 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include - +#include #include "ppsspp_config.h" #ifdef _WIN32 @@ -64,10 +64,6 @@ size_t truncate_cpy(char *dest, size_t destSize, std::string_view src) { } } -const char* safe_string(const char* s) { - return s ? s : "(null)"; -} - long parseHexLong(const std::string &s) { long value = 0; @@ -187,38 +183,6 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar } } -bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension) -{ - if (full_path.empty()) - return false; - - size_t dir_end = full_path.find_last_of("/" - // windows needs the : included for something like just "C:" to be considered a directory -#ifdef _WIN32 - ":" -#endif - ); - if (std::string::npos == dir_end) - dir_end = 0; - else - dir_end += 1; - - size_t fname_end = full_path.rfind('.'); - if (fname_end < dir_end || std::string::npos == fname_end) - fname_end = full_path.size(); - - if (_pPath) - *_pPath = full_path.substr(0, dir_end); - - if (_pFilename) - *_pFilename = full_path.substr(dir_end, fname_end - dir_end); - - if (_pExtension) - *_pExtension = full_path.substr(fname_end); - - return true; -} - std::string LineNumberString(const std::string &str) { std::stringstream input(str); std::stringstream output; @@ -291,7 +255,7 @@ void DataToHexString(const uint8_t *data, size_t size, std::string *output, bool buffer.TakeAll(output); } -void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output) { +void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string *output) { Buffer buffer; size_t i = 0; for (; i < size; i++) { @@ -321,8 +285,7 @@ void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t buffer.TakeAll(output); } -std::string StringFromFormat(const char* format, ...) -{ +std::string StringFromFormat(const char* format, ...) { va_list args; std::string temp; #ifdef _WIN32 @@ -361,27 +324,7 @@ std::string StringFromInt(int value) { return temp; } -// Turns " hej " into "hej". Also handles tabs. -std::string StripSpaces(const std::string &str) { - const size_t s = str.find_first_not_of(" \t\r\n"); - if (std::string::npos != s) - return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); - else - return ""; -} - -// "\"hello\"" is turned to "hello" -// This one assumes that the string has already been space stripped in both -// ends, as done by StripSpaces above, for example. -std::string StripQuotes(const std::string& s) -{ - if (s.size() && '\"' == s[0] && '\"' == *s.rbegin()) - return s.substr(1, s.size() - 2); - else - return s; -} - -// Turns " hej " into "hej". Also handles tabs. +// Turns " hej " into "hej". Also handles tabs and line breaks. std::string_view StripSpaces(std::string_view str) { const size_t s = str.find_first_not_of(" \t\r\n"); if (std::string::npos != s) @@ -418,7 +361,7 @@ void SplitString(std::string_view str, const char delim, std::vector &output) { +void SplitString(std::string_view str, const char delim, std::vector &output, bool trimOutput) { size_t next = 0; size_t pos = 0; while (pos < str.length()) { @@ -427,6 +370,9 @@ void SplitString(std::string_view str, const char delim, std::vector &v) { + std::unordered_set seen; + std::vector result; + result.reserve(v.size()); // minimize reallocations + for (const auto &s : v) { + if (seen.insert(s).second) { + // insert returns {iterator, bool} + // bool == true if it was newly inserted (didn't already exist) + result.push_back(s); + } + } + v.swap(result); +} diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 05caafb1a9..585e9bb773 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -90,14 +90,11 @@ enum class StringRestriction { std::string SanitizeString(std::string_view username, StringRestriction restriction, int minLength = 0, int maxLength = -1); void DataToHexString(const uint8_t *data, size_t size, std::string *output, bool lineBreaks = true); -void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output); +void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string *output); std::string StringFromFormat(const char* format, ...); std::string StringFromInt(int value); -std::string StripSpaces(const std::string &s); -std::string StripQuotes(const std::string &s); - std::string_view KeepAfterLast(std::string_view s, char c); std::string_view KeepIncludingLast(std::string_view s, char c); @@ -111,7 +108,7 @@ int CountChar(std::string_view haystack, char needle); // NOTE: str must live at least as long as all uses of output. void SplitString(std::string_view str, const char delim, std::vector &output); // Try to avoid this when possible, in favor of the string_view version. -void SplitString(std::string_view str, const char delim, std::vector &output); +void SplitString(std::string_view str, const char delim, std::vector &output, bool trimOutput = false); void GetQuotedStrings(std::string_view str, std::vector &output); @@ -134,7 +131,9 @@ inline size_t truncate_cpy(char(&out)[Count], std::string_view src) { return truncate_cpy(out, Count, src); } -const char* safe_string(const char* s); +inline const char *safe_string(const char *s) { + return s ? s : "(null)"; +} long parseHexLong(const std::string &s); long parseLong(std::string s); @@ -150,8 +149,7 @@ inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...) va_end(args); } -// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe" -bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension); +void MakeUnique(std::vector &vec); // Replaces %1, %2, %3 in format with arg1, arg2, arg3. // Much safer than snprintf and friends. diff --git a/Common/System/System.h b/Common/System/System.h index 5e594f2d62..f984c01faf 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -311,7 +311,7 @@ bool System_AudioRecordingIsAvailable(); bool System_AudioRecordingState(); // This will be changed to take an enum. Replacement for the old NativeMessageReceived. -void System_PostUIMessage(UIMessage message, const std::string ¶m = ""); +void System_PostUIMessage(UIMessage message, std::string_view param = ""); // For these functions, most platforms will use the implementation provided in UI/AudioCommon.cpp, // no need to implement separately. diff --git a/Core/Config.cpp b/Core/Config.cpp index 7c6b4d4fe6..bf813c3bcd 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -548,7 +548,9 @@ int Config::NextValidBackend() { #endif // They've all failed. Let them try the default - or on Android, OpenGL. - sFailedGPUBackends += ",ALL"; + if (sFailedGPUBackends.find(",ALL") == std::string::npos) { + sFailedGPUBackends += ",ALL"; + } ERROR_LOG(Log::Loader, "All graphics backends failed"); #if PPSSPP_PLATFORM(ANDROID) return (int)GPUBackend::OPENGL; diff --git a/Core/ConfigSettings.cpp b/Core/ConfigSettings.cpp index 5c17b58d5b..f6aed72bb0 100644 --- a/Core/ConfigSettings.cpp +++ b/Core/ConfigSettings.cpp @@ -1,6 +1,7 @@ #include "Common/Data/Format/IniFile.h" #include "Common/Net/URL.h" #include "Common/Log.h" +#include "Common/StringUtils.h" #include "Core/ConfigSettings.h" #include "Core/ConfigValues.h" @@ -38,8 +39,14 @@ bool ConfigSetting::Get(const Section *section) const { case TYPE_STRING: return section->Get(iniKey_, ptr_.s, cb_.s ? cb_.s().c_str() : default_.s); case TYPE_STRING_VECTOR: + { // No support for callbacks for these yet. that's not an issue. - return section->Get(iniKey_, ptr_.v, default_.v); + bool success = section->Get(iniKey_, ptr_.v, default_.v); + if (success) { + MakeUnique(*ptr_.v); + } + return success; + } case TYPE_TOUCH_POS: { ConfigTouchPos defaultTouchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos; diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index b6a609abff..ef67ee3ba4 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -268,7 +268,7 @@ void MemSlabMap::Slab::DoState(PointerWrap &p) { } else { std::string stringTag; Do(p, stringTag); - truncate_cpy(tag, stringTag.c_str()); + truncate_cpy(tag, stringTag); } } diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 1e69ae5e3b..4a6ac820bc 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -1442,7 +1442,7 @@ bool SavedataParam::GetSize(SceUtilitySavedataParam *param) { // TODO: Is this after the specified files? Probably before? param->sizeInfo->freeKB = (int)(freeBytes / 1024); std::string spaceTxt = SavedataParam::GetSpaceText(freeBytes, false); - truncate_cpy(param->sizeInfo->freeString, spaceTxt.c_str()); + truncate_cpy(param->sizeInfo->freeString, spaceTxt); if (writeBytes - overwriteBytes < (s64)freeBytes) { param->sizeInfo->neededKB = 0; diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index c1e81556eb..4ad3332a27 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -521,7 +521,7 @@ void InitLocalhostIP() { g_localhostIP.in.sin_addr.s_addr = htonl(localIP); g_localhostIP.in.sin_port = 0; - std::string serverStr = StripSpaces(g_Config.proAdhocServer); + std::string serverStr(StripSpaces(g_Config.proAdhocServer)); isLocalServer = (!strcasecmp(serverStr.c_str(), "localhost") || serverStr.find("127.") == 0); } diff --git a/Core/MIPS/JitCommon/JitCommon.cpp b/Core/MIPS/JitCommon/JitCommon.cpp index 104ef69d3e..38d9367aac 100644 --- a/Core/MIPS/JitCommon/JitCommon.cpp +++ b/Core/MIPS/JitCommon/JitCommon.cpp @@ -190,7 +190,7 @@ static bool Arm64SymbolCallback(char *buffer, int bufsize, uint8_t *address) { if (MIPSComp::jit) { std::string name; if (MIPSComp::jit->DescribeCodePtr(address, name)) { - truncate_cpy(buffer, bufsize, name.c_str()); + truncate_cpy(buffer, bufsize, name); return true; } } @@ -283,7 +283,7 @@ const char *ppsspp_resolver(struct ud*, std::lock_guard guard(MIPSComp::jitLock); if (MIPSComp::jit && MIPSComp::jit->DescribeCodePtr((u8 *)(uintptr_t)addr, str)) { *offset = 0; - truncate_cpy(buf, sizeof(buf), str.c_str()); + truncate_cpy(buf, sizeof(buf), str); return buf; } return NULL; diff --git a/Core/Replay.cpp b/Core/Replay.cpp index 0392e76e33..0ada57ca94 100644 --- a/Core/Replay.cpp +++ b/Core/Replay.cpp @@ -531,7 +531,7 @@ static void ConvertToTm(struct tm *t, int64_t sec) { ReplayFileInfo ConvertFileInfo(const PSPFileInfo &data) { ReplayFileInfo info; - truncate_cpy(info.filename, data.name.c_str()); + truncate_cpy(info.filename, data.name); info.size = data.size; info.access = (uint16_t)data.access; info.exists = data.exists ? 1 : 0; diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index a78e8e70eb..082624fabd 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -130,7 +130,7 @@ void MainWindow::loadAct() { QFileInfo info(filename); g_Config.currentDirectory = Path(info.absolutePath().toStdString()); - System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, filename.toStdString().c_str()); + System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, filename.toStdString()); } } diff --git a/SDL/CocoaBarItems.mm b/SDL/CocoaBarItems.mm index 2c607e9ca4..a76cbe02f7 100644 --- a/SDL/CocoaBarItems.mm +++ b/SDL/CocoaBarItems.mm @@ -641,7 +641,7 @@ TOGGLE_METHOD(FullScreen, g_Config.bFullScreen, System_MakeRequest(SystemRequest } -(void)openRecentItem: (NSMenuItem *)item { - System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, g_recentFiles.GetRecentFiles()[item.tag].c_str()); + System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, g_recentFiles.GetRecentFiles()[item.tag]); } -(void)openSystemFileBrowser { diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index a4b2782b2e..c6b296aee5 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -1222,7 +1222,7 @@ void FrameDumpTestScreen::update() { // We rely slightly on nginx listing format here. Not great. SplitString(listingHtml, '\n', lines); for (auto &line : lines) { - std::string trimmed = StripSpaces(line); + std::string trimmed(StripSpaces(line)); if (startsWith(trimmed, "GetFunctionStart(curAddress_); if (funcBegin_ != -1) { - truncate_cpy(funcNameTemp_, g_symbolMap->GetLabelString(funcBegin_).c_str()); + truncate_cpy(funcNameTemp_, g_symbolMap->GetLabelString(funcBegin_)); renameFunctionPopup = true; statusBarText_ = funcNameTemp_; } else { @@ -1327,7 +1327,7 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro if (ImGui::Selectable(symCache_[i].name.c_str(), selectedSymbol_ == i)) { disasmView_.gotoAddr(symCache_[i].address); disasmView_.scrollAddressIntoView(); - truncate_cpy(selectedSymbolName_, symCache_[i].name.c_str()); + truncate_cpy(selectedSymbolName_, symCache_[i].name); selectedSymbol_ = i; } } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 6ac569b5fc..8421e409fe 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -672,6 +672,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch } if (forceLogLevel) { + NOTICE_LOG(Log::System, "Setting log level to %d due to command line override", (int)logLevel); g_logManager.SetAllLogLevels(logLevel); } @@ -1508,11 +1509,11 @@ void NativeAccelerometer(float tiltX, float tiltY, float tiltZ) { HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Z] = tiltZ; } -void System_PostUIMessage(UIMessage message, const std::string &value) { +void System_PostUIMessage(UIMessage message, std::string_view param) { std::lock_guard lock(g_pendingMutex); PendingMessage pendingMessage; pendingMessage.message = message; - pendingMessage.value = value; + pendingMessage.value = param; pendingMessages.push_back(pendingMessage); } diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index fbab54cc61..c16613dcca 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -986,7 +986,7 @@ void CtrlDisAsmView::onMouseUp(WPARAM wParam, LPARAM lParam, int button) { char name[256]; std::string newname; - truncate_cpy(name, g_symbolMap->GetLabelString(funcBegin).c_str()); + truncate_cpy(name, g_symbolMap->GetLabelString(funcBegin)); if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), L"New function name", name, newname)) { g_symbolMap->SetLabelName(newname.c_str(), funcBegin); u32 funcSize = g_symbolMap->GetFunctionSize(funcBegin); diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index e762c24363..5f2bc85c31 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -908,8 +908,8 @@ namespace MainWindow if (!MainThread_Ready()) return DefWindowProc(hWnd, message, wParam, lParam); - HDROP hdrop = (HDROP)wParam; - int count = DragQueryFile(hdrop, 0xFFFFFFFF, 0, 0); + const HDROP hdrop = (HDROP)wParam; + const int count = DragQueryFile(hdrop, 0xFFFFFFFF, 0, 0); if (count != 1) { // TODO: Translate? Or just not bother? MessageBox(hwndMain, L"You can only load one file at a time", L"Error", MB_ICONINFORMATION); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index a381cb2be2..09931f3865 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1621,7 +1621,6 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeActivity_requestExitVulkanR _assert_(g_renderLoopThread.joinable()); exitRenderLoop = true; g_renderLoopThread.join(); - _assert_(!g_renderLoopThread.joinable()); g_renderLoopThread = std::thread(); } diff --git a/android/src/org/ppsspp/ppsspp/LifeCycle.java b/android/src/org/ppsspp/ppsspp/LifeCycle.java new file mode 100644 index 0000000000..42a988c743 --- /dev/null +++ b/android/src/org/ppsspp/ppsspp/LifeCycle.java @@ -0,0 +1,86 @@ +package org.ppsspp.ppsspp; + +import androidx.annotation.NonNull; +import android.util.Log; + +// Simple class to validate the app lifecycle progression. +// Useful to debug using logs. +public class LifeCycle { + private final String TAG = "PPSSPPNativeActivity"; + + public enum State { + LAUNCHED, + CREATED, + STARTED, + RUNNING; + + @NonNull + @Override + public String toString() { + // Optional: return a custom string if needed + return name(); // "LAUNCHED", "CREATED", etc. + } + } + + private State state = State.LAUNCHED; + + public boolean onCreate() { + if (state != State.LAUNCHED) { + Log.e(TAG, "Lifecycle: onCreate, but state is " + state + ". Expected LAUNCHED"); + return false; + } + Log.i(TAG, "onCreate begin"); + state = State.CREATED; + return true; + } + + public boolean onStart() { + if (state != State.CREATED) { + Log.e(TAG, "Lifecycle: onStart, but state is " + state + ". Expected CREATED"); + return false; + } + Log.i(TAG, "onStart begin"); + state = State.STARTED; + return true; + } + + public boolean onResume() { + if (state != State.STARTED) { + Log.e(TAG, "Lifecycle: onResume, but state is " + state + ". Expected STARTED"); + return false; + } + state = State.RUNNING; + Log.i(TAG, "onResume begin"); + return true; + } + + public boolean onPause() { + if (state != State.RUNNING) { + Log.e(TAG, "Lifecycle: onPause, but state is " + state + ". Expected RUNNING"); + return false; + } + state = State.STARTED; + Log.i(TAG, "onPause begin"); + return true; + } + + public boolean onStop() { + if (state != State.STARTED) { + Log.e(TAG, "Lifecycle: onStop, but state is " + state + ". Expected STARTED"); + return false; + } + state = State.CREATED; + Log.i(TAG, "onStop begin"); + return true; + } + + public boolean onDestroy() { + if (state != State.CREATED) { + Log.e(TAG, "Lifecycle: onDestroy, but state is " + state + ". Expected CREATED"); + return false; + } + state = State.CREATED; + Log.i(TAG, "onDestroy begin"); + return true; + } +} diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 6f8ebe3e02..631b9af173 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -71,6 +71,9 @@ public abstract class NativeActivity extends Activity implements SensorEventList // False to use Vulkan, queried from C++ after NativeApp.init. private static boolean javaGL = true; + // Lifecycle tracker, to detect erroneous states. + private final LifeCycle lifeCycle = new LifeCycle(); + // Graphics and audio interfaces for Vulkan (javaGL = false) private NativeSurfaceView mSurfaceView; private Surface mSurface; @@ -578,7 +581,7 @@ public abstract class NativeActivity extends Activity implements SensorEventList public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Log.i(TAG, "onCreate begin"); + lifeCycle.onCreate(); mSensorManager = (SensorManager)getSystemService(Activity.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); @@ -706,12 +709,12 @@ public abstract class NativeActivity extends Activity implements SensorEventList Log.i(TAG, "notifySurface begin"); mSurface = surface; - if (!initialized) { - Log.e(TAG, "notifySurface end: Can't deal with surfaces while not initialized"); - return; - } - if (!javaGL) { + if (!initialized) { + Log.e(TAG, "notifySurface end: Saving surface, but can't start/stop threads while not initialized"); + return; + } + // If we got a surface, this starts the thread. If not, it doesn't. if (mSurface == null) { joinRenderLoopThread(); @@ -766,7 +769,8 @@ public abstract class NativeActivity extends Activity implements SensorEventList @Override protected void onDestroy() { super.onDestroy(); - Log.i(TAG, "onDestroy begin"); + lifeCycle.onDestroy(); + if (javaGL) { nativeRenderer = null; mGLSurfaceView = null; @@ -808,9 +812,22 @@ public abstract class NativeActivity extends Activity implements SensorEventList Log.i(TAG, "onDestroy end"); } + @Override + protected void onStart() { + super.onStart(); + lifeCycle.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + lifeCycle.onStop(); + } + @Override protected void onPause() { super.onPause(); + lifeCycle.onPause(); if (!javaGL) { Log.i(TAG, "Joining render thread..."); @@ -820,8 +837,6 @@ public abstract class NativeActivity extends Activity implements SensorEventList mGLSurfaceView.onPause(); } - Log.i(TAG, "onPause begin"); - mSensorManager.unregisterListener(this); loseAudioFocus(this.audioManager, this.audioFocusChangeListener); @@ -836,8 +851,7 @@ public abstract class NativeActivity extends Activity implements SensorEventList @Override protected void onResume() { super.onResume(); - - Log.i(TAG, "onResume begin"); + lifeCycle.onResume(); updateSustainedPerformanceMode(); sizeManager.onResume(); diff --git a/android/src/org/ppsspp/ppsspp/SizeManager.java b/android/src/org/ppsspp/ppsspp/SizeManager.java index a8607c6762..e3510361fc 100644 --- a/android/src/org/ppsspp/ppsspp/SizeManager.java +++ b/android/src/org/ppsspp/ppsspp/SizeManager.java @@ -224,9 +224,9 @@ public class SizeManager implements SurfaceHolder.Callback { safeInsetRight = cutout.getSafeInsetRight(); safeInsetTop = cutout.getSafeInsetTop(); safeInsetBottom = cutout.getSafeInsetBottom(); - Log.i(TAG, "Safe insets: left: " + safeInsetLeft + " right: " + safeInsetRight + " top: " + safeInsetTop + " bottom: " + safeInsetBottom); + // Log.i(TAG, "Safe insets: left: " + safeInsetLeft + " right: " + safeInsetRight + " top: " + safeInsetTop + " bottom: " + safeInsetBottom); } else { - Log.i(TAG, "Safe insets: Cutout was null"); + // Log.i(TAG, "Safe insets: Cutout was null"); safeInsetLeft = 0; safeInsetRight = 0; safeInsetTop = 0; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 3fa6094274..60b38f2eeb 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -93,7 +93,7 @@ bool System_GetPropertyBool(SystemProperty prop) { } } void System_Notify(SystemNotification notification) {} -void System_PostUIMessage(UIMessage message, const std::string ¶m) {} +void System_PostUIMessage(UIMessage message, std::string_view param) {} void System_RunOnMainThread(std::function) {} bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int64_t param3, int64_t param4) { switch (type) { diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 9dea246397..9f805f25f3 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1999,7 +1999,7 @@ void System_Notify(SystemNotification notification) { } } bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int64_t param3, int64_t param4) { return false; } -void System_PostUIMessage(UIMessage message, const std::string ¶m) {} +void System_PostUIMessage(UIMessage message, std::string_view param) {} void System_RunOnMainThread(std::function) {} void NativeFrame(GraphicsContext *graphicsContext) {} void NativeResized() {} diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index d9c0d38877..f967c574a9 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -112,7 +112,7 @@ bool System_GetPropertyBool(SystemProperty prop) { } } void System_Notify(SystemNotification notification) {} -void System_PostUIMessage(UIMessage message, const std::string ¶m) {} +void System_PostUIMessage(UIMessage message, std::string_view param) {} void System_RunOnMainThread(std::function) {} void System_AudioGetDebugStats(char *buf, size_t bufSize) { if (buf) buf[0] = '\0'; } void System_AudioClear() {}