Fixed double freeing.

This commit is contained in:
nitko12 2020-09-21 15:21:25 +02:00
parent a17e1e0c69
commit 1e635111d0
5 changed files with 10 additions and 18 deletions

View File

@ -26,8 +26,8 @@ void loop()
// Display the maze // Display the maze
void showMaze(const char *maze, int width, int height) void showMaze(const char *maze, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; ++y)
for (int x = 0; x < width; x++) for (int x = 0; x < width; ++x)
if (maze[x + y * width] == 1) if (maze[x + y * width] == 1)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {

View File

@ -37,10 +37,7 @@ class Image : virtual public NetworkClient, virtual public Adafruit_GFX
const char *fileName, int x, int y, bool dither = 0, bool invert = 0); const char *fileName, int x, int y, bool dither = 0, bool invert = 0);
bool drawBitmapFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0); bool drawBitmapFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0);
[[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawBitmapFromWeb(const char *url, bool drawBitmapFromWeb(const char *url, int x, int y, bool dither = 0, bool invert = 0);
int x, int y,
bool dither = 0,
bool invert = 0);
bool drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0); bool drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0);
bool drawJpegFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert); bool drawJpegFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert);

View File

@ -109,7 +109,7 @@ bool Image::drawBitmapFromSd(SdFile *p, int x, int y, bool dither, bool invert)
bool Image::drawBitmapFromWeb(const char *url, int x, int y, bool dither, bool invert) bool Image::drawBitmapFromWeb(const char *url, int x, int y, bool dither, bool invert)
{ {
bool ret = 0; bool ret = 0;
int32_t defaultLen = 800 * 600 * 4; int32_t defaultLen = 800 * 600 * 4 + 150;
uint8_t *buf = downloadFile(url, &defaultLen); uint8_t *buf = downloadFile(url, &defaultLen);
ret = drawBitmapFromBuffer(buf, x, y, dither, invert); ret = drawBitmapFromBuffer(buf, x, y, dither, invert);
@ -132,6 +132,7 @@ bool Image::drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dit
bool Image::drawBitmapFromBuffer(uint8_t *buf, int x, int y, bool dither, bool invert) bool Image::drawBitmapFromBuffer(uint8_t *buf, int x, int y, bool dither, bool invert)
{ {
bitmapHeader bmpHeader; bitmapHeader bmpHeader;
readBmpHeader(buf, &bmpHeader); readBmpHeader(buf, &bmpHeader);
if (!legalBmp(&bmpHeader)) if (!legalBmp(&bmpHeader))
@ -148,7 +149,6 @@ bool Image::drawBitmapFromBuffer(uint8_t *buf, int x, int y, bool dither, bool i
bufferPtr += ROWSIZE(bmpHeader.width, bmpHeader.color); bufferPtr += ROWSIZE(bmpHeader.width, bmpHeader.color);
} }
free(buf);
return 1; return 1;
} }
@ -163,7 +163,7 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
switch (c) switch (c)
{ {
case 1: case 1:
writePixel(x + j, y, (invert ^ (palette[0] < palette[1])) ^ !!(pixelBuffer[j >> 3] & (1 << (7 - (j & 7))))); writePixel(x + j, y, (invert ^ (palette[0] > palette[1])) ^ !!(pixelBuffer[j >> 3] & (1 << (7 - (j & 7)))));
break; break;
// as for 2 bit, literally cannot find an example online or in PS, so skipped // as for 2 bit, literally cannot find an example online or in PS, so skipped
case 4: { case 4: {

View File

@ -29,7 +29,7 @@ void setup()
display.begin(); display.begin();
display.joinAP("", ""); display.joinAP("e-radionica.com", "croduino");
Serial.println(); Serial.println();
delay(500); delay(500);

View File

@ -1,17 +1,13 @@
#include "Inkplate.h" #include "Inkplate.h"
#include "SdFat.h"
const int n = 500; Inkplate display(INKPLATE_1BIT);
Inkplate display(INKPLATE_3BIT);
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
display.begin(); display.begin();
Serial.println(display.joinAP("e-radionica.com", "croduino"));
display.joinAP("", "");
delay(500); delay(500);
} }
@ -20,8 +16,7 @@ void loop()
{ {
display.clearDisplay(); display.clearDisplay();
display.sdCardInit(); Serial.println(display.drawBitmapFromWeb("http://img.cale.es/bmp/fasani/5e5ff140694ee", 0, 0, 1, 0));
display.drawPngFromSd("png.png", 0, 0, 1, 0);
display.display(); display.display();
delay(5000); delay(5000);