1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 12:33:17 +01:00

Fix #16308: Use void* on Android and Any on other platforms

This commit is contained in:
lawrence
2022-03-24 22:52:40 +01:00
committed by Gymnasiast
parent ed08654bfa
commit 4c14d38325

View File

@@ -70,7 +70,12 @@ namespace GameActions
CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL };
money32 Cost = 0;
ExpenditureType Expenditure = ExpenditureType::Count;
std::shared_ptr<void> ResultData;
// Any_cast throws a bad_any_cast exception on Android
// To avoid this in the Android release, a shared void pointer is used to store the result data.
// Other platforms still use Any as this provides type checks
std::shared_ptr<void> ResultDataPtr;
std::any ResultData;
Result() = default;
Result(GameActions::Status error, rct_string_id title, rct_string_id message, uint8_t* args = nullptr);
@@ -82,13 +87,21 @@ namespace GameActions
// is still just uint32_t, this guarantees the data is associated with the correct type.
template<typename T> void SetData(const T&& data)
{
ResultData = std::make_shared<T>(data);
#ifdef __ANDROID__
ResultDataPtr = std::make_shared<T>(data);
#else
ResultData = std::forward<const T&&>(data);
#endif
}
template<typename T> T GetData() const
{
T* res = static_cast<T*>(ResultData.get());
return *res;
#ifdef __ANDROID__
return *static_cast<T*>(ResultDataPtr.get());;
#else
// This function will throw std::bad_any_cast if the type mismatches.
return std::any_cast<T>(ResultData);
#endif
}
};