Prevent crash when trying to set UIntProperties using Number type (closes #2720)

This commit is contained in:
Alexander Bock
2023-06-01 09:26:41 +02:00
parent ea5ab3835d
commit 0c49bcf027
2 changed files with 15 additions and 0 deletions

View File

@@ -45,6 +45,9 @@ public:
int typeLua() const override;
using TemplateProperty<unsigned int>::operator=;
private:
unsigned int fromLuaConversion(lua_State* state) const override;
};
} // namespace openspace::properties

View File

@@ -48,4 +48,16 @@ int UIntProperty::typeLua() const {
return LUA_TNUMBER;
}
unsigned int UIntProperty::fromLuaConversion(lua_State* state) const {
if (ghoul::lua::hasValue<double>(state)) {
return static_cast<int>(ghoul::lua::value<double>(state));
}
else if (ghoul::lua::hasValue<unsigned int>(state)) {
return ghoul::lua::value<unsigned int>(state);
}
else {
throw ghoul::RuntimeError(fmt::format("Error extracting value in UIntProperty"));
}
}
} // namespace openspace::properties