Howdy Y'all,
I'm seeing crashes in a place that I don't expect it -- when I allocate heap memory, for example like reassigning a String, or call "new" in C++ code. The codebase is small, and "new (nothrow)..." doesn't work to hack around and null test.
So, as an example of what I'm talking about -- I have a program similar to the example code below ( the example is totally made up and untested -- it might work ).
I've seen the board crash the second time I make this call:
m_RandomJunk = String("");
Can anyone give me a hint as to why, or how to debug through it?
---
#include <Arduino.h>
class TotallyMadeUpInPost {
public:
TotallyMadeUpInPost();
void DoSomething();
String Get();
private:
String m_RandomJunk;
};
TotallyMadeUpInPost::TotallyMadeUpInPost() { m_RandomJunk = String("Hello there"); }
void TotallyMadeUpInPost:: DoSomething() { m_RandomJunk = String(""); m_RandomJunk += String("General Kenobi"); }
String TotallyMadeUpInPost::Get() {return(m_RandomJunk);}
TotallyMadeUpInPost RandomStuff;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.Println(RandomStuff.Get());
RandomStuff.DoSomething();
delay(200); // rate limiting.
}
I'm seeing crashes in a place that I don't expect it -- when I allocate heap memory, for example like reassigning a String, or call "new" in C++ code. The codebase is small, and "new (nothrow)..." doesn't work to hack around and null test.
So, as an example of what I'm talking about -- I have a program similar to the example code below ( the example is totally made up and untested -- it might work ).
I've seen the board crash the second time I make this call:
m_RandomJunk = String("");
Can anyone give me a hint as to why, or how to debug through it?
---
#include <Arduino.h>
class TotallyMadeUpInPost {
public:
TotallyMadeUpInPost();
void DoSomething();
String Get();
private:
String m_RandomJunk;
};
TotallyMadeUpInPost::TotallyMadeUpInPost() { m_RandomJunk = String("Hello there"); }
void TotallyMadeUpInPost:: DoSomething() { m_RandomJunk = String(""); m_RandomJunk += String("General Kenobi"); }
String TotallyMadeUpInPost::Get() {return(m_RandomJunk);}
TotallyMadeUpInPost RandomStuff;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.Println(RandomStuff.Get());
RandomStuff.DoSomething();
delay(200); // rate limiting.
}