bitbank2 / PNGenc

An embedded-friendly PNG encoder
Apache License 2.0
39 stars 8 forks source link

ESP32 Pico D4 encountered InstrFetchProhibited Issue at addRGB565Lines #7

Closed CMUBOB97 closed 2 years ago

CMUBOB97 commented 2 years ago

Hello bitbank! Hope you are doing good!

I was trying to compress a 160 * 120 rgb565 image into a png file using ESP32-Pico-D4. I defined the PNG class and everything executed properly until I hit addRGB565Lines. Here is my code and error log:

PNG png;

void PNG_encode() {

  int rc;
  uint8_t tempLine[1280]; // 160 pixels per line, so it should be more than enough to hold one line of pixels

  Serial.println("mallocing...");
  pOutput = (uint8_t *)malloc(160 * 120);

  // open the png image
  Serial.println("opening png...");
  rc = png.open(pOutput, 160*120);
  Serial.println("opening png success");

  if (rc != PNG_SUCCESS) {
    Serial.println("Error opening the output file");
    return;
  }

  // begin png encoder
  Serial.println("initializing encoder...");
  rc = png.encodeBegin(160, 120, PNG_PIXEL_TRUECOLOR, 24, NULL, 9);
  Serial.println("encoder initialized");

  // encoding line by line
  if (rc == PNG_SUCCESS) {
    Serial.println("add RGB565 lines...");
    for (int y = 0; y < 120 && rc == PNG_SUCCESS; y++) {
      rc = png.addRGB565Line(&rgb565Buffer[160 * y], (void *)tempLine);
    }
  } else {
    Serial.println("Error beginning the encoder");
  }
  Serial.println("png compressed");

  // get the output
  if (rc == PNG_SUCCESS) {
    Serial.println("getting png size...");
    iDataSize = png.close();
  } else {
    Serial.println("Error encoding the png file");
  }
  Serial.println("png size fetched");

}

And here is my error log:

setup complete!
mallocing...
opening png...
opening png success
initializing encoder...
encoder initialized
add RGB565 lines...
Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x00000000  PS      : 0x00060230  A0      : 0x800d9749  A1      : 0x3ffb0ec0  
A2      : 0x3ffc189c  A3      : 0x00000000  A4      : 0x3ffcc7f6  A5      : 0x00000054  
A6      : 0x00000050  A7      : 0x84003984  A8      : 0x800d91be  A9      : 0x3ffb0ea0  
A10     : 0x3ffc18e8  A11     : 0x3ffcc7f6  A12     : 0x00000029  A13     : 0x000002cd  
A14     : 0x000002cd  A15     : 0x00000003  SAR     : 0x0000001d  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00000000  LBEG    : 0x400d8e15  LEND    : 0x400d8e21  LCOUNT  : 0x00000000  

ELF file SHA256: 0000000000000000

The error code says that CPU accessed an invalid address for instruction. The PC went to zero instead of locating at a valid instruction address (0x4xxxxxxx). Details about this error can be found here.

Any clue for this error is appreciated!

bitbank2 commented 2 years ago

Can you post a complete example? How is rgb565Buffer defined? It may be something simple.

bitbank2 commented 2 years ago

closing for lack of activity