Skip to content

Commit bc1affb

Browse files
committed
Added empty buffer check for image download
1 parent 22dd021 commit bc1affb

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/include/ImageBMP.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ bool Image::drawBitmapFromWeb(const char *url, int x, int y, bool dither, bool i
222222
buf = downloadFileHTTPS(url, &defaultLen);
223223
}
224224

225+
// Image sometimes doesn't download, so
226+
// check if buffer is empty to avoid trying to draw an empty image
227+
if (!buf)
228+
return 0;
229+
225230
ret = drawBitmapFromBuffer(buf, x, y, dither, invert);
226231
free(buf);
227232

@@ -251,6 +256,11 @@ bool Image::drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dit
251256
bool ret = 0;
252257
uint8_t *buf = downloadFile(s, len);
253258

259+
// Image sometimes doesn't download, so
260+
// check if buffer is empty to avoid trying to draw an empty image
261+
if (!buf)
262+
return 0;
263+
254264
ret = drawBitmapFromBuffer(buf, x, y, dither, invert);
255265
free(buf);
256266

@@ -520,6 +530,11 @@ bool Image::drawBmpFromWebAtPosition(const char *url, const Position &position,
520530
int32_t defaultLen = E_INK_WIDTH * E_INK_HEIGHT * 4 + 150;
521531
uint8_t *buf = downloadFileHTTPS(url, &defaultLen);
522532

533+
// Image sometimes doesn't download, so
534+
// check if buffer is empty to avoid trying to draw an empty image
535+
if (!buf)
536+
return 0;
537+
523538
bitmapHeader bmpHeader;
524539
readBmpHeader(buf, &bmpHeader);
525540

src/include/ImageJPEG.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ bool Image::drawJpegFromWeb(const char *url, int x, int y, bool dither, bool inv
134134
buf = downloadFileHTTPS(url, &defaultLen);
135135
}
136136

137+
// Image sometimes doesn't download, so
138+
// check if buffer is empty to avoid trying to draw an empty image
139+
if (!buf)
140+
return 0;
141+
137142
ret = drawJpegFromBuffer(buf, defaultLen, x, y, dither, invert);
138143
free(buf);
139144

@@ -172,6 +177,11 @@ bool Image::drawJpegFromWebAtPosition(const char *url, const Position &position,
172177
buff = downloadFileHTTPS(url, &defaultLen);
173178
}
174179

180+
// Image sometimes doesn't download, so
181+
// check if buffer is empty to avoid trying to draw an empty image
182+
if (!buff)
183+
return 0;
184+
175185
uint16_t w = 0;
176186
uint16_t h = 0;
177187
TJpgDec.setJpgScale(1);
@@ -288,6 +298,12 @@ bool Image::drawJpegFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dithe
288298
{
289299
bool ret = 0;
290300
uint8_t *buff = downloadFile(s, len);
301+
302+
// Image sometimes doesn't download, so
303+
// check if buffer is empty to avoid trying to draw an empty image
304+
if (!buff)
305+
return 0;
306+
291307
ret = drawJpegFromBuffer(buff, len, x, y, dither, invert);
292308
free(buff);
293309

src/include/ImagePNG.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ bool Image::drawPngFromWeb(const char *url, int x, int y, bool dither, bool inve
233233
buf = downloadFileHTTPS(url, &defaultLen);
234234
}
235235

236+
// Image sometimes doesn't download, so
237+
// check if buffer is empty to avoid trying to draw an empty image
236238
if (!buf)
237239
return 0;
238240

@@ -280,6 +282,8 @@ bool Image::drawPngFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither
280282

281283
uint8_t *buff = downloadFile(s, len);
282284

285+
// Image sometimes doesn't download, so
286+
// check if buffer is empty to avoid trying to draw an empty image
283287
if (!buff)
284288
return 0;
285289

@@ -325,6 +329,8 @@ bool Image::drawPngFromWebAtPosition(const char *url, const Position &position,
325329
int32_t defaultLen = E_INK_WIDTH * E_INK_HEIGHT * 4 + 100;
326330
uint8_t *buff = downloadFile(url, &defaultLen);
327331

332+
// Image sometimes doesn't download, so
333+
// check if buffer is empty to avoid trying to draw an empty image
328334
if (!buff)
329335
return 0;
330336

0 commit comments

Comments
 (0)