Skip to content

Commit acd5c65

Browse files
author
Adafruit Adabot
committed
fix sad alloc
1 parent 3568baf commit acd5c65

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

M4_Eyes/M4_Eyes.ino

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ void setup() {
140140
arcada.displayBegin();
141141
// MUST set up flash filesystem before Serial.begin() or seesaw.begin()
142142
if (!arcada.filesysBeginMSD()) {
143-
arcada.setBacklight(255);
144-
arcada.haltBox("No filesystem found, please load CircuitPython on in order to create one!");
143+
fatal("No filesystem found!", 100);
145144
}
146145

147146
Serial.begin(115200);
148-
while(!Serial) delay(10);
147+
//while(!Serial) delay(10);
149148

150149
Serial.printf("Available RAM at start: %d\n", availableRAM());
151150
Serial.printf("Available flash at start: %d\n", availableNVM());
@@ -246,10 +245,7 @@ void setup() {
246245
eye[e].blinkFactor = 0.0;
247246
}
248247

249-
analogWrite(BACKLIGHT_PIN, 255);
250-
#if defined(SEESAW_BACKLIGHT_PIN)
251-
arcada.ss.analogWrite(SEESAW_BACKLIGHT_PIN, 255);
252-
#endif
248+
arcada.setBacklight(255);
253249

254250
// LOAD CONFIGURATION FILE -----------------------------------------------
255251

M4_Eyes/file.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,11 @@ ImageReturnCode loadEyelid(char *filename,
335335
// This is the "booster seat" described in m4eyes.ino
336336
if(reader->bmpDimensions(filename, &w, &h) == IMAGE_SUCCESS) {
337337
tempBytes = ((w + 7) / 8) * h; // Bitmap size in bytes
338-
if(tempPtr = (uint8_t *)malloc(maxRam - tempBytes)) {
339-
// Make SOME tempPtr reference, or optimizer removes the alloc!
340-
tempPtr[0] = 0;
338+
if (maxRam > tempBytes) {
339+
if(tempPtr = (uint8_t *)malloc(maxRam - tempBytes)) {
340+
// Make SOME tempPtr reference, or optimizer removes the alloc!
341+
tempPtr[0] = 0;
342+
}
341343
}
342344
// DON'T nest the image-reading case in here. If the fragmentation
343345
// culprit can be found, this block of code (and the free() block
@@ -416,9 +418,11 @@ ImageReturnCode loadTexture(char *filename, uint16_t **data,
416418
// This is the "booster seat" described in m4eyes.ino
417419
if(reader->bmpDimensions(filename, &w, &h) == IMAGE_SUCCESS) {
418420
tempBytes = w * h * 2; // Image size in bytes (converted to 16bpp)
419-
if(tempPtr = (uint8_t *)malloc(maxRam - tempBytes)) {
420-
// Make SOME tempPtr reference, or optimizer removes the alloc!
421-
tempPtr[0] = 0;
421+
if (maxRam > tempBytes) {
422+
if(tempPtr = (uint8_t *)malloc(maxRam - tempBytes)) {
423+
// Make SOME tempPtr reference, or optimizer removes the alloc!
424+
tempPtr[0] = 0;
425+
}
422426
}
423427
// DON'T nest the image-reading case in here. If the fragmentation
424428
// culprit can be found, this block of code (and the free() block

M4_Eyes/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// GLOBAL VARIABLES --------------------------------------------------------
2626

27-
GLOBAL_VAR uint32_t stackReserve GLOBAL_INIT(8192); // See image-loading code
27+
GLOBAL_VAR uint32_t stackReserve GLOBAL_INIT(5192); // See image-loading code
2828
GLOBAL_VAR int eyeRadius GLOBAL_INIT(0); // 0 = Use default in loadConfig()
2929
GLOBAL_VAR int eyeDiameter; // Calculated from eyeRadius later
3030
GLOBAL_VAR int irisRadius GLOBAL_INIT(60); // Approx size in screen pixels

0 commit comments

Comments
 (0)