From 84cafe238754498f1eabe405a58ade588084a92a Mon Sep 17 00:00:00 2001 From: Adam Wonak Date: Sat, 16 Aug 2025 09:51:05 -0700 Subject: [PATCH] Fix bug in metadata save/load state. The sketch_name char array was to short, causing a buffer overflow. --- firmware/Gravity/Gravity.ino | 8 +++++++- firmware/Gravity/save_state.cpp | 6 +++--- firmware/Gravity/save_state.h | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/firmware/Gravity/Gravity.ino b/firmware/Gravity/Gravity.ino index aef4ab8..f9bd119 100644 --- a/firmware/Gravity/Gravity.ino +++ b/firmware/Gravity/Gravity.ino @@ -228,7 +228,13 @@ void HandleEncoderPressed() { if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) { app.selected_save_slot = app.selected_sub_param; stateManager.loadData(app, app.selected_save_slot); - InitGravity(app); + if (gravity.clock.Tempo() != app.tempo) { + gravity.clock.SetTempo(app.tempo); + } + // If clock is active, just load the pattern, do not change other global state. + if (gravity.clock.IsPaused()) { + InitGravity(app); + } } break; case PARAM_MAIN_FACTORY_RESET: diff --git a/firmware/Gravity/save_state.cpp b/firmware/Gravity/save_state.cpp index ff00005..ef32b6c 100644 --- a/firmware/Gravity/save_state.cpp +++ b/firmware/Gravity/save_state.cpp @@ -2,7 +2,7 @@ * @file save_state.cpp * @author Adam Wonak (https://github.com/awonak/) * @brief Alt firmware version of Gravity by Sitka Instruments. - * @version 2.0.1 + * @version 2.0.0 * @date 2025-07-04 * * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com @@ -55,8 +55,8 @@ bool StateManager::loadData(AppState& app, byte slot_index) { // Load the state data from the specified EEPROM slot and update the app state save slot. _loadState(app, slot_index); app.selected_save_slot = slot_index; - // Persist this change in the global metadata. - _saveMetadata(app); + // Persist this change in the global metadata on next update. + _isDirty = true; return true; } diff --git a/firmware/Gravity/save_state.h b/firmware/Gravity/save_state.h index 29226e7..50f4f03 100644 --- a/firmware/Gravity/save_state.h +++ b/firmware/Gravity/save_state.h @@ -2,7 +2,7 @@ * @file save_state.h * @author Adam Wonak (https://github.com/awonak/) * @brief Alt firmware version of Gravity by Sitka Instruments. - * @version 2.0.1 + * @version 2.0.0 * @date 2025-07-04 * * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com @@ -52,8 +52,8 @@ class StateManager { // This struct holds the data that identifies the firmware version. struct Metadata { - char sketch_name[12]; - char version[5]; + char sketch_name[16]; + char version[16]; // Additional global/hardware settings byte selected_save_slot; bool encoder_reversed;