Skip to content

Commit

Permalink
#43 Make sure not to get out of bounds in vector.at(POS) Adafruit is …
Browse files Browse the repository at this point in the history
…writing a pixel in row 103 when display.height is 100 pixels max
  • Loading branch information
martinberlin committed Jul 9, 2021
1 parent 93ce48b commit 9ddfb2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/CalEPD/include/plasticlogic014.h
Expand Up @@ -39,7 +39,7 @@ class PlasticLogic014 : public PlasticLogic
//uint8_t _buffer[PLOGIC014_BUFFER_SIZE];
// Buffer sent to EPD prefixed with 0x10:
//uint8_t bufferEpd[PLOGIC014_BUFFER_SIZE+1];

bool _vec_bonds_check = true;
bool _initial = true;
bool _debug_buffer = false;
uint16_t _nextline = PLOGIC014_WIDTH/4;
Expand Down
10 changes: 10 additions & 0 deletions components/CalEPD/models/plasticlogic/plasticlogic014.cpp
Expand Up @@ -124,6 +124,15 @@ void PlasticLogic014::drawPixel(int16_t x, int16_t y, uint16_t color) {
y=y+3;
uint16_t pos = x/4 + (y) * _nextline;

// check that is not going to write out of Vector bonds
// #43 TODO: Check why is trying to update out of bonds anyways
if (pos >= _buffer.size()) {
if (_vec_bonds_check) {
printf("x:%d y:%d Vpos:%d >out bonds\n",x,y, pos);
_vec_bonds_check = false;
}
return;
}
uint8_t pixels = _buffer.at(pos);
uint8_t pixel = 0xff;

Expand All @@ -135,4 +144,5 @@ void PlasticLogic014::drawPixel(int16_t x, int16_t y, uint16_t color) {
}
buffer_it = _buffer.begin()+pos;
*(buffer_it) = pixel;

}

0 comments on commit 9ddfb2a

Please sign in to comment.