mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-21 17:40:54 +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:
parent
f472dc1158
commit
4944f0ff04
@ -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++;
|
||||
if(!DocWillOverflow)
|
||||
{
|
||||
control->MarshalControl(item, InUpdateMode, DataOffset);
|
||||
}
|
||||
|
||||
if (rootDoc.overflowed() || (ESPUI.jsonChunkNumberMax > 0 && (elementcount % ESPUI.jsonChunkNumberMax) == 0))
|
||||
if (DocWillOverflow || (ESPUI.jsonChunkNumberMax > 0 && (elementcount % ESPUI.jsonChunkNumberMax) == 0))
|
||||
{
|
||||
// String("prepareJSONChunk: too much data in the message. Remove the last entry");
|
||||
if (1 == elementcount)
|
||||
|
Loading…
Reference in New Issue
Block a user