Compilation error: grpc: received message larger than max (4322345 vs. 4194304)

I'm trying to get familiar with the ESP32 S2 Mini. As a start, I wanted to include a few 16-bit bitmaps in the code to see how fast it would work and interact with the display. I connected a 320x240 resolution, 16-bit color display to the chip. I set the partition scheme to (huge APP 3MB, No OTA, 1MB SPIFFS). In the code, I added the bitmaps as constants – const uint16_t PROGMEM pic6[] = {0x94B1, 0x94B2, 0x94B2 ..., one bitmap being 320x240x2, which is 153600 bytes in FLASH memory. Everything worked fine after adding the 6th bitmap. During the upload, I received the following message in the console:

Sketch uses 1163034 bytes (36%) of program storage space. Maximum is 3145728 bytes. Global variables use 15336 bytes (4%) of dynamic memory, leaving 312344 bytes for local variables. Maximum is 327680 bytes.

So, it was okay, and I thought I'd add more bitmaps. But after adding another one, the console showed an error:

grpc: received message larger than max (4322345 vs. 4194304) Compilation error: grpc: received message larger than max (4322345 vs. 4194304)

Adding another 150KB bitmap caused the following error:

grpc: received message larger than max (4939180 vs. 4194304) Compilation error: grpc: received message larger than max (4939180 vs. 4194304)

So, adding another 153600 bytes bitmap increased the message overflow by another 616835 bytes. I'm not sure if it has something to do with the length of the project itself. Each 2-byte bitmap entry takes up 8 characters/bytes in the program code, like "0xFFFF."

Does anyone know how to fix this or where to change the maximum message size ?

Are your bitmaps in a separate file .h file or in ino files. If the latter, try to place them in one or more .h files and include those in the main ino file.

I do not know if you can change the size; there might be a config somewhere but I did not look.

Some search, not specific to the Arduino IDE:
https://www.google.com/search?q=grpc%3A+received+message+larger+than+max

I placed the bitmaps in a separate .h file as suggested and I managed to upload 2 more bitmaps to the project, with the 9th one the same error. Maybe splitting the .h file with bitmaps for smaller allows me to upload more bitmaps. The project itself is a test.

Hi @jacek_kander. Please post a sketch that produces the error in a reply here on the forum thread. I'd like to investigate this problem, but I first need to be able to reproduce it on my own computer.

We typically want sketches to be posted as text in the forum post itself. However, in this case where the sketch is very large, that will not be possible due to it exceeding the maximum post character limit. So you should provide the sketch files as attachments in your reply. I'll provide instructions you can follow to do that:

  1. Open a forum reply here by clicking the "Reply" button.
  2. Click the "Upload" icon (Upload icon) on the post composer toolbar:
    Upload icon on toolbar
    The "Open" dialog will open.
  3. Select the file from the "Open" dialog.
  4. Click the "Open" button.
    The dialog will close.
  5. Repeat the above steps for each of the remaining files of the sketch.
  6. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (2) - (4) above, you can simply drag and drop the file onto the post composer field to attach it.

I noticed that after opening the project I can upload it to the chip without an error, but adding even a space symbol in any line causes the error to be displayed again. I tested with IDE version 2.2.1 and 2.3.3

Picture_320x240_Error.zip (849.8 KB)

If the sketch in post #5 (it has 8 bitmaps) is the one that does not compile on your system, I can not reproduce the problem when compiling for a Lolin S2 Mini.

Win11 / Intel I3 / 16GB
IDE 2.3.3
ESP32 board package version 3.0.5
Board Lolin S2 Mini

If you selected another board, please let us know.
If you're using an other ESP32 board package version, please let us know.

FQBN: esp32:esp32:lolin_s2_mini:PartitionScheme=huge_app
Using board 'lolin_s2_mini' from platform in folder: C:\Users\bugge\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5
Using core 'esp32' from platform in folder: C:\Users\bugge\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5
...
...
Sketch uses 1701934 bytes (54%) of program storage space. Maximum is 3145728 bytes.
Global variables use 26368 bytes (8%) of dynamic memory, leaving 301312 bytes for local variables. Maximum is 327680 bytes.

I've also tried it with a portable install of IDE 1.8.19 and ESP32 board package version 3.0.4 and it compiled as well (but that might not use RPC, I do not know).

I started Arduino after a break when I received a new ESP32. It seems it was my fault, I updated all libraries and boards definitions and the error disappeared. Thank you for your help and time.

Thanks @jacek_kander. With the sketch you provided I was able to reproduce the error. I did an investigation and submitted a formal report to the developers:

I don't think any of that caused it to disappear. The fault only occurs when the sketch is in a "dirty" (unsaved) state in Arduino IDE. You probably stopped experiencing it because you have been compiling the sketch when it is a saved state. If you have Arduino IDE's "Auto save" preference enabled, then the sketch will always be in a saved state, but if you turn that preference off, make a change to the sketch, then compile while the sketch is in that "dirty" state that is indicated by a ⬀ at the right side of the editor tab, you will surely still encounter the error.

You are right, I have the "auto save" option turned off. Some time after writing the last reply the error appeared later again during further modifications of the project. Before I read your reply I checked the project on another computer but I did not experience this error there, maybe because there was a fresh Arduino IDE in which I did not have time to disable the "auto save" option. In the end I thought it was my laptop's fault and that maybe it was time to reinstall a fresh Windows.

The Arduino developers implemented a mitigation for the problem last week, which was to increase the maximum sketch file size from 4 MB to 16 MB. The fix was made after the time of the last Arduino IDE release, and hasn't even been pulled into the Arduino IDE nightly builds yet, but this does mean that, except in the case of ridiculously huge sketch files, the problem should not occur for users of the future releases of Arduino IDE, even when the "Auto save" feature is disabled.