Skip to content

Commit 8027d22

Browse files
committed
Make frame counter unsigned when it is used in calculations
Otherwise the arrays will index out of bounds when the frame counter overflows. Discovered via the YNOOnline project were savegames that are used for multiple years can happen :)
1 parent 1922266 commit 8027d22

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/scene_battle_rpg2k3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ void Scene_Battle_Rpg2k3::UpdateAnimations() {
421421
}
422422
}
423423

424-
auto frame_counter = Main_Data::game_system->GetFrameCounter();
424+
auto frame_counter = static_cast<uint32_t>(Main_Data::game_system->GetFrameCounter());
425425

426426
bool ally_set = false;
427427
if (status_window->GetActive()

src/tilemap_layer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static constexpr uint8_t BlockD_Subtiles_IDS[50][2][2][2] = {
143143
// Set of neighboring autotiles -> autotile variant
144144
// Each neighbor is represented by a single bit (1 - same autotile, 0 - any other case)
145145
// The bits are ordered as follows (from most to least significant bit): NW N NE W E SW S SE
146-
static const std::unordered_map<uint8_t, int> AUTOTILE_D_VARIANTS_MAP = { //it also works with A
146+
static const std::unordered_map<uint8_t, int> AUTOTILE_D_VARIANTS_MAP = { //it also works with A
147147
{0b11111111, 0},
148148
{0b01111111, 1},
149149
{0b11011111, 2},
@@ -285,7 +285,7 @@ void TilemapLayer::Draw(Bitmap& dst, uint8_t z_order, int render_ox, int render_
285285
};
286286

287287
// FIXME: When Game_Map singleton is made an object we can remove this null check
288-
const auto frames = Main_Data::game_system ? Main_Data::game_system->GetFrameCounter() : 0;
288+
const auto frames = Main_Data::game_system ? static_cast<uint32_t>(Main_Data::game_system->GetFrameCounter()) : 0u;
289289
auto animation_step_c = (frames / 6) % 4;
290290
auto animation_step_ab = frames / animation_speed;
291291
if (animation_type) {

0 commit comments

Comments
 (0)