mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
fix: Multiple memory corruption issues
This commit is contained in:
@@ -17,18 +17,25 @@ namespace hex {
|
||||
AutoReset<std::string> s_imageTheme;
|
||||
AutoReset<std::string> s_currTheme;
|
||||
|
||||
std::mutex s_themeMutex;
|
||||
}
|
||||
|
||||
|
||||
void ThemeManager::addThemeHandler(const std::string &name, const ColorMap &colorMap, const std::function<ImColor(u32)> &getFunction, const std::function<void(u32, ImColor)> &setFunction) {
|
||||
std::unique_lock lock(s_themeMutex);
|
||||
|
||||
(*s_themeHandlers)[name] = { colorMap, getFunction, setFunction };
|
||||
}
|
||||
|
||||
void ThemeManager::addStyleHandler(const std::string &name, const StyleMap &styleMap) {
|
||||
std::unique_lock lock(s_themeMutex);
|
||||
|
||||
(*s_styleHandlers)[name] = { styleMap };
|
||||
}
|
||||
|
||||
void ThemeManager::addTheme(const std::string &content) {
|
||||
std::unique_lock lock(s_themeMutex);
|
||||
|
||||
try {
|
||||
auto theme = nlohmann::json::parse(content);
|
||||
|
||||
@@ -106,6 +113,8 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ThemeManager::changeTheme(std::string name) {
|
||||
std::unique_lock lock(s_themeMutex);
|
||||
|
||||
if (!s_themes->contains(name)) {
|
||||
if (s_themes->empty()) {
|
||||
return;
|
||||
@@ -168,12 +177,12 @@ namespace hex {
|
||||
const float scale = style.needsScaling ? 1_scaled : 1.0F;
|
||||
|
||||
if (value.is_number_float()) {
|
||||
if (const auto newValue = std::get_if<float*>(&style.value); newValue != nullptr)
|
||||
if (const auto newValue = std::get_if<float*>(&style.value); newValue != nullptr && *newValue != nullptr)
|
||||
**newValue = value.get<float>() * scale;
|
||||
else
|
||||
log::warn("Style variable '{}' was of type ImVec2 but a float was expected.", name);
|
||||
} else if (value.is_array() && value.size() == 2 && value[0].is_number_float() && value[1].is_number_float()) {
|
||||
if (const auto newValue = std::get_if<ImVec2*>(&style.value); newValue != nullptr)
|
||||
if (const auto newValue = std::get_if<ImVec2*>(&style.value); newValue != nullptr && *newValue != nullptr)
|
||||
**newValue = ImVec2(value[0].get<float>() * scale, value[1].get<float>() * scale);
|
||||
else
|
||||
log::warn("Style variable '{}' was of type float but a ImVec2 was expected.", name);
|
||||
@@ -191,6 +200,8 @@ namespace hex {
|
||||
hex::log::error("Theme '{}' has invalid image theme!", name);
|
||||
s_imageTheme = "dark";
|
||||
}
|
||||
} else {
|
||||
s_imageTheme = "dark";
|
||||
}
|
||||
|
||||
s_currTheme = name;
|
||||
@@ -211,6 +222,8 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ThemeManager::reset() {
|
||||
std::unique_lock lock(s_themeMutex);
|
||||
|
||||
s_themes->clear();
|
||||
s_styleHandlers->clear();
|
||||
s_themeHandlers->clear();
|
||||
|
||||
Reference in New Issue
Block a user