Fix devicestate protobuf / filesize allocation (#5835)

This commit is contained in:
Ben Meadors 2025-01-13 08:30:20 -06:00 committed by GitHub
parent 6366633cd4
commit e2dd845051
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
@ -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)