aboutsummaryrefslogtreecommitdiff
path: root/src/common/settings_setting.h
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2026-06-14 20:48:24 +0200
committercrueter <crueter@eden-emu.dev>2026-06-14 20:48:24 +0200
commit60e10327715e420f652ed148e72e22ce8ded55a3 (patch)
tree8ab3722ac19e31d61e85e7134ebfe4232b1bc540 /src/common/settings_setting.h
parent10713532917591445080bee19159447b683b548a (diff)
[qt] fix various crashes due to invalid/corrupted/outdated settings (#4070)
lots of "out of index" errors :) Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4070 Reviewed-by: crueter <crueter@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Diffstat (limited to 'src/common/settings_setting.h')
-rw-r--r--src/common/settings_setting.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h
index 076aceef29..9b6ec76d62 100644
--- a/src/common/settings_setting.h
+++ b/src/common/settings_setting.h
@@ -11,6 +11,7 @@
#include <optional>
#include <stdexcept>
#include <string>
+#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <fmt/core.h>
@@ -101,7 +102,15 @@ public:
* @param val The desired value
*/
virtual void SetValue(const Type& val) {
- Type temp{ranged ? std::clamp(val, minimum, maximum) : val};
+ // Enums have a maximal range which they're allowed
+ Type temp{};
+ if constexpr (std::is_enum_v<Type>) {
+ auto const r_min = std::underlying_type_t<Type>(0);
+ auto const r_max = std::underlying_type_t<Type>(EnumMetadata<Type>::GetLast());
+ temp = Type(std::clamp(std::underlying_type_t<Type>(val), r_min, r_max));
+ } else {
+ temp = ranged ? std::clamp(val, this->minimum, this->maximum) : val;
+ }
std::swap(value, temp);
}
@@ -129,7 +138,7 @@ protected:
} else if constexpr (std::is_floating_point_v<Type>) {
return fmt::format("{:f}", value_);
} else if constexpr (std::is_enum_v<Type>) {
- return std::to_string(u32(value_));
+ return std::to_string(std::underlying_type_t<Type>(value_));
} else {
return std::to_string(value_);
}
@@ -371,7 +380,15 @@ public:
* @param val The new value
*/
void SetValue(const Type& val) override final {
- Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val};
+ // Enums have a maximal range which they're allowed
+ Type temp{};
+ if constexpr (std::is_enum_v<Type>) {
+ auto const r_min = std::underlying_type_t<Type>(0);
+ auto const r_max = std::underlying_type_t<Type>(EnumMetadata<Type>::GetLast());
+ temp = Type(std::clamp(std::underlying_type_t<Type>(val), r_min, r_max));
+ } else {
+ temp = ranged ? std::clamp(val, this->minimum, this->maximum) : val;
+ }
if (use_global) {
std::swap(this->value, temp);
} else {