From 5f417987bc5d2b69ea7c7a8132875df4f1030852 Mon Sep 17 00:00:00 2001 From: lawrence Date: Mon, 21 Mar 2022 22:36:59 +0100 Subject: [PATCH 1/4] Fix #16308: Crash when trying to place down a ride on Android --- src/openrct2/actions/GameActionResult.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/actions/GameActionResult.h b/src/openrct2/actions/GameActionResult.h index e79eeb6811..4d1973c1b0 100644 --- a/src/openrct2/actions/GameActionResult.h +++ b/src/openrct2/actions/GameActionResult.h @@ -70,7 +70,7 @@ namespace GameActions CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL }; money32 Cost = 0; ExpenditureType Expenditure = ExpenditureType::Count; - std::any ResultData; + std::shared_ptr ResultData; Result() = default; Result(GameActions::Status error, rct_string_id title, rct_string_id message, uint8_t* args = nullptr); @@ -82,13 +82,13 @@ 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::forward(data); + ResultData = std::make_shared(data); } - // This function will throw std::bad_any_cast if the type mismatches. template T GetData() const { - return std::any_cast(ResultData); + T* res = static_cast(ResultData.get()); + return *res; } }; From ed08654bfac9a22879ec64ed7b449103aa8c9cbe Mon Sep 17 00:00:00 2001 From: lawrence Date: Tue, 22 Mar 2022 23:06:26 +0100 Subject: [PATCH 2/4] Fix #16308: Update changelog --- contributors.md | 1 + distribution/changelog.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/contributors.md b/contributors.md index d00eaef55b..f74586273a 100644 --- a/contributors.md +++ b/contributors.md @@ -186,6 +186,7 @@ The following people are not part of the development team, but have been contrib * Rik Smeets (rik-smeets) * Charles Machalow (csm10495) * Alexander Czarnecki (alcz/zuczek4793) +* Lawrence De Mol (lawrencedemol) ## Toolchain * (Balletie) - macOS diff --git a/distribution/changelog.txt b/distribution/changelog.txt index c87689564e..b509de56ce 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -63,6 +63,7 @@ - Fix: [#16162] Go Karts speeds are not correctly randomised, they only go very fast or very slow. - Fix: [#16188] Medium-size banked turns on the Twister and Vertical Roller Coaster have incorrect support placement (partly original bug). - Fix: [#16264, #16572] Placing saved track design crashes game. +- Fix [#16308] Crash when trying to place down a ride on Android. - Fix: [#16327] Crash on malformed network packet. - Fix: [#16449] [Plugin] Viewport doesn't hide when switching tabs. - Fix: [#16450] Banner style not copied when using tile inspector. From 4c14d38325dcdd297351addcc6e5602e70225342 Mon Sep 17 00:00:00 2001 From: lawrence Date: Thu, 24 Mar 2022 22:52:40 +0100 Subject: [PATCH 3/4] Fix #16308: Use void* on Android and Any on other platforms --- src/openrct2/actions/GameActionResult.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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 } }; From ab86d195104b952e878fb85e5dc5b31281b45c2d Mon Sep 17 00:00:00 2001 From: tupaschoal Date: Mon, 28 Mar 2022 20:40:53 +0200 Subject: [PATCH 4/4] Apply review requests --- src/openrct2/actions/GameActionResult.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/openrct2/actions/GameActionResult.h b/src/openrct2/actions/GameActionResult.h index 29b4802602..1dce6e8b78 100644 --- a/src/openrct2/actions/GameActionResult.h +++ b/src/openrct2/actions/GameActionResult.h @@ -71,11 +71,14 @@ namespace GameActions money32 Cost = 0; ExpenditureType Expenditure = ExpenditureType::Count; +#ifdef __ANDROID__ // 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. + std::shared_ptr ResultData; +#else // Other platforms still use Any as this provides type checks - std::shared_ptr ResultDataPtr; std::any ResultData; +#endif Result() = default; Result(GameActions::Status error, rct_string_id title, rct_string_id message, uint8_t* args = nullptr); @@ -88,7 +91,7 @@ namespace GameActions template void SetData(const T&& data) { #ifdef __ANDROID__ - ResultDataPtr = std::make_shared(data); + ResultData = std::make_shared(data); #else ResultData = std::forward(data); #endif @@ -97,7 +100,8 @@ namespace GameActions template T GetData() const { #ifdef __ANDROID__ - return *static_cast(ResultDataPtr.get());; + return *static_cast(ResultData.get()); + ; #else // This function will throw std::bad_any_cast if the type mismatches. return std::any_cast(ResultData);