Warning! GxEPD2 display.setPartialWindow uses unsigned integers

Hi
First post so please be gentle. I'm really appreciating GxEPD2 and all the work Jean-Marc has put into it! I know this is entirely user error but I was just putting it out there in case anyone has had similar headaches as I'm pretty sure this has been the source of my ESP32-S3 hanging on several occasions (won't boot after Upload) depsite no errors/warnings according to the compiler (via both Arduino IDE and PlatformIO Arduino framework).

Essentially, this happens if I miscalculate the bounding box of some characters and accidentally pass a negative value to:

setPartialWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)

I have mistakenly passed a negative y value when using the top of the screen. It can be a little confusing because the bounding box (x, y) is the top left corner whereas the cursor position is at the bottom of the character for displaying character fonts. Also, the values returned/modified by display.getTextBounds and u8g2Fonts.getFontAscent/Descent are signed integers. Therefore I am sure my board hanging has been the result of undefined behaviour passing a negative y value to setPartialWindow.

This is completely my fault but it was time consuming to troubleshoot for a relative novice. Now that I understand the danger of undefined behaviour I will refactor my code with the appropriate safeguards. I was also wondering whether it might be possible to modify setPartialWindow to have int arguments and default to zero if negative values are passed to avoid undefined behaviour? I understand that using unsigned types uses less storage but with these displays typically being used by MCUs with more memory than a Uno it shouldn't make a significant difference. Also, Adafruit_GFX::getTextBounds uses signed integers for co-ordinate values both of the cursor and upper left corner of the bounding box. I have submitted a request to the GxEPD2 GitHub repository just as a suggestion and fully accept that Jean-Marc may well reject it.

Dan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.