Skip to content

Commit

Permalink
Fix devicestate protobuf / filesize allocation (#5835)
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern authored Jan 13, 2025
1 parent 6366633 commit e2dd845
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ void NodeDB::loadFromDisk()
#endif

// static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM
auto state = loadProto(prefFileName, sizeof(meshtastic_DeviceState) + MAX_NUM_NODES_FS * sizeof(meshtastic_NodeInfo),
auto state = loadProto(prefFileName, sizeof(meshtastic_DeviceState) + MAX_NUM_NODES_FS * meshtastic_NodeInfoLite_size,
sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate);

// See https://github.com/meshtastic/firmware/issues/4184#issuecomment-2269390786
Expand Down Expand Up @@ -1147,8 +1147,9 @@ bool NodeDB::saveDeviceStateToDisk()
#endif
// Note: if MAX_NUM_NODES=100 and meshtastic_NodeInfoLite_size=166, so will be approximately 17KB
// Because so huge we _must_ not use fullAtomic, because the filesystem is probably too small to hold two copies of this
return saveProto(prefFileName, sizeof(devicestate) + numMeshNodes * meshtastic_NodeInfoLite_size, &meshtastic_DeviceState_msg,
&devicestate, false);
size_t deviceStateSize;
pb_get_encoded_size(&deviceStateSize, meshtastic_DeviceState_fields, &devicestate);
return saveProto(prefFileName, deviceStateSize, &meshtastic_DeviceState_msg, &devicestate, false);
}

bool NodeDB::saveToDiskNoRetry(int saveWhat)
Expand Down

0 comments on commit e2dd845

Please sign in to comment.