diff --git a/Common/Thread/ThreadUtil.cpp b/Common/Thread/ThreadUtil.cpp index a67e1e65ac..8d60ea6140 100644 --- a/Common/Thread/ThreadUtil.cpp +++ b/Common/Thread/ThreadUtil.cpp @@ -30,10 +30,11 @@ AttachDetachFunc g_detach; void AttachThreadToJNI() { if (g_attach) { g_attach(); + } else { + ERROR_LOG(Log::System, "Couldn't attach thread - g_attach not set"); } } - void DetachThreadFromJNI() { if (g_detach) { g_detach(); diff --git a/Core/HLE/AtracCtx2.h b/Core/HLE/AtracCtx2.h index afd4956677..2a5554df66 100644 --- a/Core/HLE/AtracCtx2.h +++ b/Core/HLE/AtracCtx2.h @@ -45,7 +45,7 @@ public: void CheckForSas() override; int EnqueueForSas(u32 address, u32 ptr) override; void DecodeForSas(s16 *dstData, int *bytesWritten, int *finish) override; - const AtracSasStreamState *StreamStateForSas() const { return context_->info.state == 0x10 ? &sas_ : nullptr; } + const AtracSasStreamState *StreamStateForSas() const override { return context_->info.state == 0x10 ? &sas_ : nullptr; } u32 GetNextSamples() override; diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 10cc036fdc..834c92d526 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -1352,7 +1352,7 @@ PPGeImage::PPGeImage(std::string_view pspFilename) PPGeImage::PPGeImage(u32 pngPointer, size_t pngSize) : filename_(""), png_(pngPointer), size_(pngSize) { if (!Memory::IsValidRange(this->png_, (u32)this->size_)) { - WARN_LOG(Log::sceGe, "Created PPGeImage from invalid memory range %08x (%08x bytes). Will not be drawn."); + WARN_LOG(Log::sceGe, "Created PPGeImage from invalid memory range %08x (%08x bytes). Will not be drawn.", this->png_, (int)this->size_); } } @@ -1374,7 +1374,7 @@ bool PPGeImage::Load() { _dbg_assert_(size_ < MAX_VALID_IMAGE_SIZE); const u8 *srcPtr = Memory::GetPointerRange(png_, (u32)size_); if (!srcPtr) { - ERROR_LOG(Log::sceGe, "Trying to load PPGeImage from invalid range: %08x, %08x bytes", png_, size_); + ERROR_LOG(Log::sceGe, "Trying to load PPGeImage from invalid range: %08x, %08x bytes", png_, (int)size_); return false; } success = pngLoadPtr(srcPtr, size_, &width_, &height_, &textureData); diff --git a/Core/Util/RecentFiles.cpp b/Core/Util/RecentFiles.cpp index 2354cda783..8a9f044451 100644 --- a/Core/Util/RecentFiles.cpp +++ b/Core/Util/RecentFiles.cpp @@ -13,19 +13,31 @@ RecentFilesManager g_recentFiles; -RecentFilesManager::RecentFilesManager() { - thread_ = std::thread([this] { - ThreadFunc(); - }); -} +RecentFilesManager::RecentFilesManager() {} RecentFilesManager::~RecentFilesManager() { - { - std::lock_guard guard(cmdLock_); - cmds_.push(RecentCommand{ RecentCmd::Exit }); - cmdCondVar_.notify_one(); + if (thread_.joinable()) { + { + std::lock_guard guard(cmdLock_); + cmds_.push(RecentCommand{ RecentCmd::Exit }); + cmdCondVar_.notify_one(); + } + thread_.join(); } - thread_.join(); +} + +void RecentFilesManager::EnsureThread() { + if (thread_.joinable()) { + return; + } + std::lock_guard guard(cmdLock_); + thread_ = std::thread([this] { + // NOTE: Can't create the thread in the constructor, because at that point, + // JNI attachment doesn't yet work. + SetCurrentThreadName("RecentISOThreadFunc"); + AndroidJNIThreadContext jniContext; // destructor detaches + ThreadFunc(); + }); } std::vector RecentFilesManager::GetRecentFiles() const { @@ -137,9 +149,6 @@ void RecentFilesManager::Clean() { } void RecentFilesManager::ThreadFunc() { - SetCurrentThreadName("RecentISOs"); - AndroidJNIThreadContext jniContext; // destructor detaches - while (true) { RecentCommand cmd; { diff --git a/Core/Util/RecentFiles.h b/Core/Util/RecentFiles.h index 1384d13a69..cb11de83bf 100644 --- a/Core/Util/RecentFiles.h +++ b/Core/Util/RecentFiles.h @@ -29,8 +29,11 @@ public: void Clear(); bool ContainsFile(std::string_view filename); + void EnsureThread(); + std::vector GetRecentFiles() const; private: + enum class RecentCmd { Exit, Clear, @@ -58,7 +61,6 @@ private: std::thread thread_; std::mutex cmdLock_; std::condition_variable cmdCondVar_; - }; // Singleton, don't make more. diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 1960bf0a58..3c8358c335 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -1035,7 +1035,8 @@ void DrawAudioDecodersView(ImConfig &cfg, ImControl &control) { int endSample, loopStart, loopEnd; ctx->GetSoundSample(&endSample, &loopStart, &loopEnd); ImGui::ProgressBar((float)pos / (float)endSample, ImVec2(200.0f, 0.0f)); - ImGui::Text("Status: %s", AtracStatusToString(ctx->BufferState())); ImGui::Text("cur/end sample: %d/%d/%d", pos, endSample); + ImGui::Text("Status: %s", AtracStatusToString(ctx->BufferState())); + ImGui::Text("cur/end sample: %d/%d", pos, endSample); } if (ctx->context_.IsValid()) { ImGui::Text("ctx addr: "); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index cbf73a92e2..1193dd096f 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -108,6 +108,7 @@ #include "Core/Util/GameManager.h" #include "Core/Util/PortManager.h" #include "Core/Util/AudioFormat.h" +#include "Core/Util/RecentFiles.h" #include "Core/WebServer.h" #include "Core/TiltEventProcessor.h" @@ -341,6 +342,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count); + g_recentFiles.EnsureThread(); + // Make sure UI state is MENU. ResetUIState();