Merge pull request #13675 from LillyJadeKatrin/retroachievements-close-deadlock

AchievementManager - LoadGameCallback
This commit is contained in:
JMC47 2025-05-20 11:54:31 -04:00 committed by GitHub
commit 1dc4dc6b6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 51 deletions

View File

@ -58,14 +58,13 @@ AchievementManager& AchievementManager::GetInstance()
return s_instance;
}
void AchievementManager::Init(void* hwnd, AsyncCallbackHandler async_callback_handler)
void AchievementManager::Init(void* hwnd)
{
LoadDefaultBadges();
if (!m_client && Config::Get(Config::RA_ENABLED))
{
{
std::lock_guard lg{m_lock};
m_async_callback_handler = std::move(async_callback_handler);
m_client = rc_client_create(MemoryVerifier, Request);
}
std::string host_url = Config::Get(Config::RA_HOST_URL);
@ -994,22 +993,22 @@ void AchievementManager::LoadGameCallback(int result, const char* error_message,
OSD::Duration::VERY_LONG, OSD::Color::RED);
OSD::AddMessage("Please update Dolphin to a newer version.", OSD::Duration::VERY_LONG,
OSD::Color::RED);
instance.CloseGame();
return;
}
if (result == RC_NO_GAME_LOADED && instance.m_dll_found)
{
// Allow developer tools for unidentified games
rc_client_set_read_memory_function(instance.m_client, MemoryPeeker);
instance.m_system.store(&Core::System::GetInstance(), std::memory_order_release);
WARN_LOG_FMT(ACHIEVEMENTS, "Unrecognized title ready for development.");
OSD::AddMessage("Unrecognized title loaded for development.", OSD::Duration::VERY_LONG,
OSD::Color::YELLOW);
}
if (result != RC_OK)
{
WARN_LOG_FMT(ACHIEVEMENTS, "Failed to load data for current game.");
OSD::AddMessage("Achievements are not supported for this title.", OSD::Duration::VERY_LONG,
OSD::Color::RED);
if (instance.m_dll_found && result == RC_NO_GAME_LOADED)
{
// Allow developer tools for unidentified games
rc_client_set_read_memory_function(instance.m_client, MemoryPeeker);
instance.m_system.store(&Core::System::GetInstance(), std::memory_order_release);
return;
}
instance.CloseGame();
return;
}
@ -1284,18 +1283,12 @@ void AchievementManager::Request(const rc_api_request_t* request,
Common::HttpRequest::AllowedReturnCodes::All);
}
const auto response_code = http_request.GetLastResponseCode();
// The callback needs to be invoked inside our async callback handler
// as it may trigger a shutdown which will wait on this very job to complete.
AchievementManager::GetInstance().m_async_callback_handler(
[callback, callback_data, http_response = std::move(http_response), response_code] {
rc_api_server_response_t server_response;
if (http_response.has_value() && http_response->size() > 0)
{
server_response.body = reinterpret_cast<const char*>(http_response->data());
server_response.body_length = http_response->size();
server_response.http_status_code = response_code;
server_response.http_status_code = http_request.GetLastResponseCode();
}
else
{
@ -1304,9 +1297,9 @@ void AchievementManager::Request(const rc_api_request_t* request,
server_response.body_length = sizeof(error_message);
server_response.http_status_code = RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR;
}
callback(&server_response, callback_data);
});
});
}
// Currently, when rc_client calls the memory peek method provided in its constructor (or in

View File

@ -29,7 +29,6 @@
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/Event.h"
#include "Common/Functional.h"
#include "Common/HttpRequest.h"
#include "Common/JsonUtil.h"
#include "Common/Lazy.h"
@ -122,12 +121,8 @@ public:
};
using UpdateCallback = std::function<void(const UpdatedItems&)>;
using AsyncCallback = Common::MoveOnlyFunction<void()>;
using AsyncCallbackHandler = Common::MoveOnlyFunction<void(AsyncCallback)>;
static AchievementManager& GetInstance();
void Init(void* hwnd, AsyncCallbackHandler async_callback_handler);
void Init(void* hwnd);
void SetUpdateCallback(UpdateCallback callback);
void Login(const std::string& password);
bool HasAPIToken() const;
@ -313,8 +308,6 @@ private:
Common::AsyncWorkThread m_image_queue;
mutable std::recursive_mutex m_lock;
std::recursive_mutex m_filereader_lock;
AsyncCallbackHandler m_async_callback_handler;
}; // class AchievementManager
#else // USE_RETRO_ACHIEVEMENTS

View File

@ -6,12 +6,13 @@
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QString>
#include <QVBoxLayout>
#include "Core/AchievementManager.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/FreeLookSettings.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/UISettings.h"
#include "Core/Core.h"
#include "Core/Movie.h"
@ -21,7 +22,7 @@
#include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
#include "DolphinQt/QtUtils/SignalBlocking.h"
#include "DolphinQt/Settings.h"
@ -251,14 +252,9 @@ void AchievementSettingsWidget::ToggleRAIntegration()
auto& instance = AchievementManager::GetInstance();
if (Config::Get(Config::RA_ENABLED))
{
instance.Init(reinterpret_cast<void*>(winId()),
[this](auto func) { QueueOnObject(this, std::move(func)); });
}
instance.Init(reinterpret_cast<void*>(winId()));
else
{
instance.Shutdown();
}
}
void AchievementSettingsWidget::Login()

View File

@ -274,9 +274,7 @@ MainWindow::MainWindow(Core::System& system, std::unique_ptr<BootParameters> boo
NetPlayInit();
#ifdef USE_RETRO_ACHIEVEMENTS
AchievementManager::GetInstance().Init(reinterpret_cast<void*>(winId()), [this](auto func) {
QueueOnObject(this, std::move(func));
});
AchievementManager::GetInstance().Init(reinterpret_cast<void*>(winId()));
if (AchievementManager::GetInstance().IsHardcoreModeActive())
Settings::Instance().SetDebugModeEnabled(false);
// This needs to trigger on both RA_HARDCORE_ENABLED and RA_ENABLED