1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-21 12:30:55 +00:00

Arduino 7 does not report an overflow util heap is exhausted. Added a mechanism to estimate how much memory the doc is using so we can limit the number of entries in the messages

This commit is contained in:
MartinMueller2003 2024-02-29 16:34:20 -05:00
parent f472dc1158
commit 4944f0ff04

View File

@ -269,6 +269,8 @@ uint32_t ESPUIclient::prepareJSONChunk(uint16_t startindex,
// Serial.println(String("prepareJSONChunk: Start. InUpdateMode: ") + String(InUpdateMode));
int elementcount = 0;
uint32_t MaxEstimatedMarshaledJsonSize = (!InUpdateMode) ? ESPUI.jsonInitialDocumentSize: ESPUI.jsonUpdateDocumentSize;
uint32_t TotalEstimatedMarshaledJsonSize = 0;
do // once
{
@ -386,11 +388,16 @@ uint32_t ESPUIclient::prepareJSONChunk(uint16_t startindex,
}
}
TotalEstimatedMarshaledJsonSize += control->GetEstimatedMarshaledSize();
bool DocWillOverflow = TotalEstimatedMarshaledJsonSize >= MaxEstimatedMarshaledJsonSize;
JsonObject item = items.createNestedObject();
elementcount++;
control->MarshalControl(item, InUpdateMode, DataOffset);
if (rootDoc.overflowed() || (ESPUI.jsonChunkNumberMax > 0 && (elementcount % ESPUI.jsonChunkNumberMax) == 0))
if(!DocWillOverflow)
{
control->MarshalControl(item, InUpdateMode, DataOffset);
}
if (DocWillOverflow || (ESPUI.jsonChunkNumberMax > 0 && (elementcount % ESPUI.jsonChunkNumberMax) == 0))
{
// String("prepareJSONChunk: too much data in the message. Remove the last entry");
if (1 == elementcount)