mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2025-01-10 03:29:22 +01:00
Fix move constructor/operator to properly release the combo handle, use std::forward_list instead of vector for the list
This commit is contained in:
parent
7ed6058b99
commit
9a9c1c092c
@ -328,32 +328,42 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~ButtonComboWrapper() {
|
~ButtonComboWrapper() {
|
||||||
|
ReleaseButtonComboHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReleaseButtonComboHandle() {
|
||||||
if (mButtonComboHandle != nullptr) {
|
if (mButtonComboHandle != nullptr) {
|
||||||
if (const auto res = ButtonComboModule_RemoveButtonCombo(mButtonComboHandle); res != BUTTON_COMBO_MODULE_ERROR_SUCCESS) {
|
if (const auto res = ButtonComboModule_RemoveButtonCombo(mButtonComboHandle); res != BUTTON_COMBO_MODULE_ERROR_SUCCESS) {
|
||||||
DEBUG_FUNCTION_LINE_WARN("ButtonComboModule_RemoveButtonCombo for %08X returned: %s", mButtonComboHandle, ButtonComboModule_GetStatusStr(res));
|
DEBUG_FUNCTION_LINE_WARN("ButtonComboModule_RemoveButtonCombo for %08X returned: %s", mButtonComboHandle, ButtonComboModule_GetStatusStr(res));
|
||||||
}
|
}
|
||||||
|
mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonComboWrapper(const ButtonComboWrapper &) = delete;
|
ButtonComboWrapper(const ButtonComboWrapper &) = delete;
|
||||||
|
ButtonComboWrapper &operator=(ButtonComboWrapper &src) = delete;
|
||||||
|
|
||||||
ButtonComboWrapper(ButtonComboWrapper &&src) noexcept : mCreationError(src.mCreationError),
|
ButtonComboWrapper(ButtonComboWrapper &&src) noexcept : mCreationError(src.mCreationError),
|
||||||
mButtonComboHandle(src.mButtonComboHandle),
|
|
||||||
mContextData(std::move(src.mContextData)),
|
mContextData(std::move(src.mContextData)),
|
||||||
mHandle(std::move(src.mHandle)) {
|
mHandle(std::move(src.mHandle)) {
|
||||||
this->mCreationError = BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR;
|
ReleaseButtonComboHandle();
|
||||||
this->mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
|
||||||
|
mButtonComboHandle = ButtonComboModule_ComboHandle(src.mButtonComboHandle.handle);
|
||||||
|
|
||||||
|
src.mCreationError = BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR;
|
||||||
|
src.mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonComboWrapper &operator=(ButtonComboWrapper &&src) noexcept {
|
ButtonComboWrapper &operator=(ButtonComboWrapper &&src) noexcept {
|
||||||
if (this != &src) {
|
if (this != &src) {
|
||||||
|
ReleaseButtonComboHandle();
|
||||||
this->mCreationError = src.mCreationError;
|
this->mCreationError = src.mCreationError;
|
||||||
this->mButtonComboHandle = src.mButtonComboHandle;
|
this->mButtonComboHandle = ButtonComboModule_ComboHandle(src.mButtonComboHandle.handle);
|
||||||
this->mContextData = std::move(src.mContextData);
|
this->mContextData = std::move(src.mContextData);
|
||||||
this->mHandle = std::move(src.mHandle);
|
this->mHandle = std::move(src.mHandle);
|
||||||
|
|
||||||
this->mCreationError = BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR;
|
src.mCreationError = BUTTON_COMBO_MODULE_ERROR_UNKNOWN_ERROR;
|
||||||
this->mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
src.mButtonComboHandle = ButtonComboModule_ComboHandle(nullptr);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -453,8 +463,8 @@ ButtonComboManager &ButtonComboManager::operator=(ButtonComboManager &&src) {
|
|||||||
WUPSButtonCombo_Error ButtonComboManager::AddButtonComboHandle(const WUPSButtonCombo_ComboOptions &options,
|
WUPSButtonCombo_Error ButtonComboManager::AddButtonComboHandle(const WUPSButtonCombo_ComboOptions &options,
|
||||||
WUPSButtonCombo_ComboHandle &outHandle,
|
WUPSButtonCombo_ComboHandle &outHandle,
|
||||||
WUPSButtonCombo_ComboStatus &outStatus) {
|
WUPSButtonCombo_ComboStatus &outStatus) {
|
||||||
mComboWrappers.emplace_back(options, outStatus);
|
mComboWrappers.emplace_front(options, outStatus);
|
||||||
const auto &addedItem = mComboWrappers.back();
|
const auto &addedItem = mComboWrappers.front();
|
||||||
const auto handle = addedItem.getHandle();
|
const auto handle = addedItem.getHandle();
|
||||||
if (const auto res = addedItem.GetCreationError(); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
|
if (const auto res = addedItem.GetCreationError(); res != WUPS_BUTTON_COMBO_ERROR_SUCCESS) {
|
||||||
if (!remove_first_if(mComboWrappers, [&handle](const auto &comboWrapper) { return comboWrapper.getHandle() == handle; })) {
|
if (!remove_first_if(mComboWrappers, [&handle](const auto &comboWrapper) { return comboWrapper.getHandle() == handle; })) {
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <forward_list>
|
||||||
|
|
||||||
|
|
||||||
class ButtonComboWrapper;
|
class ButtonComboWrapper;
|
||||||
@ -71,6 +71,6 @@ public:
|
|||||||
[[nodiscard]] uint32_t getHandle() const;
|
[[nodiscard]] uint32_t getHandle() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ButtonComboWrapper> mComboWrappers;
|
std::forward_list<ButtonComboWrapper> mComboWrappers;
|
||||||
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
std::unique_ptr<uint32_t> mHandle = std::make_unique<uint32_t>();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user