Go Down

Topic: Fixing String Crashes (Read 1 time) previous topic - next topic

Jan 30, 2013, 12:04 am Last Edit: Mar 07, 2013, 05:33 am by Nick Gammon Reason: 1
If your having trouble with the String library crashing your sketch you might want to take a look at this site:
http://www.seti.net/Cosmic%20Rays/Engineering/engineering.htm

Nick Gammon

#1
Jan 30, 2013, 12:40 am Last Edit: Jan 30, 2013, 12:57 am by Nick Gammon Reason: 1
Good catch! I didn't realize it was that easy.




On a Mac you need to right-click to "Show Package Contents" of your app:



Then copy malloc.c to the folder as shown:






On Windows, it will be something like this (depending where you installed the Arduino app):



After installation:






In case the linked site goes down, I made a copy (right-click and "Save Link As ..."):

http://gammon.com.au/Arduino/malloc.c

Test code:

Code: [Select]

// This sketch will crash after about three iterations.
// It's caused by the malloc bug in the String library

void setup()
 {
 Serial.begin(115200);
 }  // end of setup
 
void loop()
 {
 int n = 0;
 while (n <= 100)
   {
   int u = 20 * n;
   int v = 30 * n;
   String str = String (n) + ", " + String (u) + ", " + String (v);
   Serial.println (str);
   delay (300);
   n++;
   }
 Serial.println ("Done");
 }  // end of loop

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

zoomkat

I tried something similar recently based on anothers postings on the subject, and it caused a compile failure with the SdFat library.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Nick Gammon

I just compiled my "hex uploader" program which uses SDfat and it compiled OK.

Also the SDInfo example from the SDfat distribution.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

zoomkat

Below is what I get when compiling the  quickstart sdfat code.

Code: [Select]
core.a(malloc.c.o):C:\Users\zoomkat\Desktop\Stuff\arduino IDE\arduino-1.0.1-rc2-windows\arduino-1.0.1-rc2\hardware\arduino\cores\arduino/malloc.c:194: first defined here
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Nick Gammon

That compiles OK for me, so I have to assume the SDfat author added in his own malloc.c to work around the known bugs. See if you can find a copy in your SDfat library folder.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Looks like I am right, I just checked the latest version. He probably got tired of waiting for the official fix. It is probably safe to remove his one. Unless there is some subtle problem with it.

I just did a "diff" and the file malloc.c from SdFatBeta20121203.zip, and the one alluded to above, are identical. So there should be no problems in simply deleting it.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

zoomkat

Well, will the sdfat version of malloc.c be in the compile path for librarys other than the sdfat ones?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Try running the torture test. If it fails, there is your answer.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up