Pages: [1]   Go Down
Author Topic: Fixing String Crashes  (Read 1362 times)
0 Members and 1 Guest are viewing this topic.
Near San Diego
Offline Offline
Jr. Member
**
Karma: 1
Posts: 69
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 06, 2013, 11:33:01 pm by Nick Gammon » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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

« Last Edit: January 29, 2013, 06:57:21 pm by Nick Gammon » Logged


0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9627
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried something similar recently based on anothers postings on the subject, and it caused a compile failure with the SdFat library.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Also the SDInfo example from the SDfat distribution.
Logged


0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9627
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9627
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, will the sdfat version of malloc.c be in the compile path for librarys other than the sdfat ones?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I doubt it.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try running the torture test. If it fails, there is your answer.
Logged


Pages: [1]   Go Up
Jump to: