diff --git a/src/openrct2/actions/GameActionResult.h b/src/openrct2/actions/GameActionResult.h index 4d1973c1b0..29b4802602 100644 --- a/src/openrct2/actions/GameActionResult.h +++ b/src/openrct2/actions/GameActionResult.h @@ -70,7 +70,12 @@ namespace GameActions CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL }; money32 Cost = 0; ExpenditureType Expenditure = ExpenditureType::Count; - std::shared_ptr 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 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 void SetData(const T&& data) { - ResultData = std::make_shared(data); +#ifdef __ANDROID__ + ResultDataPtr = std::make_shared(data); +#else + ResultData = std::forward(data); +#endif } template T GetData() const { - T* res = static_cast(ResultData.get()); - return *res; +#ifdef __ANDROID__ + return *static_cast(ResultDataPtr.get());; +#else + // This function will throw std::bad_any_cast if the type mismatches. + return std::any_cast(ResultData); +#endif } };