Skip to content

Commit 15e119c

Browse files
committed
fix(crash), update: Fixed integer input crash on Android, no longer target Android.
Because it keeps crashing for no reason
1 parent 7137ec7 commit 15e119c

File tree

6 files changed

+73
-53
lines changed

6 files changed

+73
-53
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ jobs:
1818
- name: macOS
1919
os: macos-latest
2020

21-
- name: Android32
22-
os: ubuntu-latest
23-
target: Android32
21+
# - name: Android32
22+
# os: ubuntu-latest
23+
# target: Android32
2424

25-
- name: Android64
26-
os: ubuntu-latest
27-
target: Android64
25+
# - name: Android64
26+
# os: ubuntu-latest
27+
# target: Android64
2828

2929
name: ${{ matrix.config.name }}
3030
runs-on: ${{ matrix.config.os }}

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [3.0.0-beta.1] - 2024-11-28
9+
10+
### Changed
11+
12+
- Target Windows and Mac only, until I find a fix for Android later
13+
- Renamed GD List ID key to "gd-list-id"
14+
15+
### Fixed
16+
17+
- Integer input layer crash on android
18+
819
## [3.0.0] - 2024-11-24
920

1021
### Added

mod.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
"geode": "4.0.1",
33
"gd": {
44
"win": "2.2074",
5-
"android": "2.2074",
65
"mac": "2.2074"
76
},
8-
"version": "v3.0.0",
7+
"version": "v3.0.0-beta.1",
98
"id": "spaghettdev.gd-roulette",
109
"name": "GD-Roulette",
1110
"developer": "SpaghettDev",

src/custom_layers/RLIntegerInputLayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void RLIntegerInputLayer::onClose(CCObject*)
9494
{
9595
try
9696
{
97-
m_integer = std::stoi(input_node->getString());
97+
m_integer = numFromString<int>(input_node->getString()).unwrapOr(m_iili.fallback_value);
9898
}
9999
catch (...)
100100
{
@@ -117,7 +117,7 @@ void RLIntegerInputLayer::onLeftButton(CCObject*)
117117
{
118118
try
119119
{
120-
m_integer = std::stoi(input_node->getString()) - 1;
120+
m_integer = numFromString<int>(input_node->getString()).unwrapOr(m_iili.fallback_value) - 1;
121121
}
122122
catch (...)
123123
{
@@ -135,7 +135,7 @@ void RLIntegerInputLayer::onRightButton(CCObject*)
135135
{
136136
try
137137
{
138-
m_integer = std::stoi(input_node->getString()) + 1;
138+
m_integer = numFromString<int>(input_node->getString()).unwrapOr(m_iili.fallback_value) + 1;
139139
}
140140
catch (...)
141141
{

src/roulette/manager/DataManager.hpp

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace DataManager
3636
};
3737

3838
const std::unordered_map<DMMiscKey, std::string_view> MISC_KEY_TO_NAME{
39-
{ DMMiscKey::GD_LIST_ID, "gdListID" },
39+
{ DMMiscKey::GD_LIST_ID, "gd-list-id" },
4040
};
4141

4242
struct SavedArrayInfo
@@ -56,6 +56,52 @@ namespace DataManager
5656
};
5757
}
5858

59+
namespace
60+
{
61+
const auto saveDataPath = geode::Mod::get()->getSaveDir() / "save_data";
62+
63+
GameState readGameState()
64+
{
65+
GameState fromDisk;
66+
std::ifstream saveDataFile(saveDataPath, std::ios::binary);
67+
saveDataFile.read(reinterpret_cast<char*>(&fromDisk), sizeof(GameState));
68+
69+
// TODO: Add checksum and integrity check here or something
70+
71+
return fromDisk;
72+
}
73+
74+
GameState writeGameStateSafe(bool force_clean = false)
75+
{
76+
std::ifstream saveDataFileIn(saveDataPath, std::ios::binary);
77+
saveDataFileIn.seekg(0, std::ios::end);
78+
79+
if (force_clean || saveDataFileIn.fail() || saveDataFileIn.tellg() != sizeof(GameState))
80+
{
81+
GameState defaultValue;
82+
83+
std::ofstream saveDataFileOut(saveDataPath, std::ios::binary);
84+
saveDataFileOut.write(reinterpret_cast<char*>(&defaultValue), sizeof(GameState));
85+
86+
return defaultValue;
87+
}
88+
89+
GameState fromDisk;
90+
saveDataFileIn.seekg(0);
91+
saveDataFileIn.read(reinterpret_cast<char*>(&fromDisk), sizeof(GameState));
92+
93+
return fromDisk;
94+
}
95+
96+
void writeGameState(const GameState& value)
97+
{
98+
std::ofstream(saveDataPath, std::ios::binary).write(
99+
reinterpret_cast<const char*>(&value),
100+
sizeof(GameState)
101+
);
102+
}
103+
}
104+
59105
namespace traits
60106
{
61107
template <DMMiscKey K>
@@ -122,17 +168,6 @@ namespace DataManager
122168
template <DMMiscKey key>
123169
[[nodiscard]] traits::KeyTrait<key>::type get()
124170
{
125-
using value_t = typename traits::KeyTrait<key>::type;
126-
127-
if constexpr (key == DMMiscKey::SAVE_DATA)
128-
{
129-
value_t fromDisk;
130-
std::ifstream saveDataFile(geode::Mod::get()->getSaveDir() / "save_data", std::ios::binary);
131-
saveDataFile.read(reinterpret_cast<char*>(&fromDisk), sizeof(value_t));
132-
133-
return fromDisk;
134-
}
135-
136171
return setDefaultSafe<key>();
137172
}
138173

@@ -173,17 +208,9 @@ namespace DataManager
173208
void set(const typename traits::KeyTrait<key>::type& value)
174209
{
175210
if constexpr (key == DMMiscKey::SAVE_DATA)
176-
{
177-
std::ofstream saveDataFile(geode::Mod::get()->getSaveDir() / "save_data");
178-
saveDataFile.write(
179-
reinterpret_cast<const char*>(&value),
180-
sizeof(typename traits::KeyTrait<key>::type)
181-
);
182-
}
211+
writeGameState(value);
183212
else
184-
{
185213
geode::Mod::get()->setSavedValue(values::MISC_KEY_TO_NAME.at(key), value);
186-
}
187214
}
188215

189216

@@ -223,26 +250,7 @@ namespace DataManager
223250
using save_container_t = std::conditional_t<std::is_same_v<value_t, int>, uint64_t, value_t>;
224251

225252
if constexpr (key == DMMiscKey::SAVE_DATA)
226-
{
227-
std::ifstream saveDataFileIn(geode::Mod::get()->getSaveDir() / "save_data", std::ios::binary);
228-
saveDataFileIn.seekg(0, std::ios::end);
229-
230-
if (saveDataFileIn.fail() || saveDataFileIn.tellg() != sizeof(value_t))
231-
{
232-
value_t defaultValue;
233-
234-
std::ofstream saveDataFileOut(geode::Mod::get()->getSaveDir() / "save_data", std::ios::binary);
235-
saveDataFileOut.write(reinterpret_cast<char*>(&defaultValue), sizeof(value_t));
236-
237-
return defaultValue;
238-
}
239-
240-
value_t fromDisk;
241-
saveDataFileIn.seekg(0);
242-
saveDataFileIn.read(reinterpret_cast<char*>(&fromDisk), sizeof(value_t));
243-
244-
return fromDisk;
245-
}
253+
return writeGameStateSafe();
246254
else
247255
{
248256
auto& container = geode::Mod::get()->getSaveContainer();

src/roulette/manager/GameState.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22

3+
static_assert(true); // clangd bug fix
4+
35
#pragma pack(push, 1)
46
struct GameState
57
{
6-
int levelID = 0;
8+
int levelID = 0;
79
int skipsUsed = 0;
810
int numLevels = 0;
911
int levelPercentage = 0;

0 commit comments

Comments
 (0)