From 0c49bcf02797c4e3841acfba9606eeb9f2bd702b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 1 Jun 2023 09:26:41 +0200 Subject: [PATCH] Prevent crash when trying to set UIntProperties using Number type (closes #2720) --- include/openspace/properties/scalar/uintproperty.h | 3 +++ src/properties/scalar/uintproperty.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/openspace/properties/scalar/uintproperty.h b/include/openspace/properties/scalar/uintproperty.h index b004d15e31..22b1abfd32 100644 --- a/include/openspace/properties/scalar/uintproperty.h +++ b/include/openspace/properties/scalar/uintproperty.h @@ -45,6 +45,9 @@ public: int typeLua() const override; using TemplateProperty::operator=; + +private: + unsigned int fromLuaConversion(lua_State* state) const override; }; } // namespace openspace::properties diff --git a/src/properties/scalar/uintproperty.cpp b/src/properties/scalar/uintproperty.cpp index b823aa5e3a..dbcb5b7403 100644 --- a/src/properties/scalar/uintproperty.cpp +++ b/src/properties/scalar/uintproperty.cpp @@ -48,4 +48,16 @@ int UIntProperty::typeLua() const { return LUA_TNUMBER; } +unsigned int UIntProperty::fromLuaConversion(lua_State* state) const { + if (ghoul::lua::hasValue(state)) { + return static_cast(ghoul::lua::value(state)); + } + else if (ghoul::lua::hasValue(state)) { + return ghoul::lua::value(state); + } + else { + throw ghoul::RuntimeError(fmt::format("Error extracting value in UIntProperty")); + } +} + } // namespace openspace::properties