Ok, this problem is weird & hard to explain, but I'll do my best. Thanks for trying to help me & others who may be seeing this too.
My full code is here (in case the code snippets below are not enough):
My code compiles successfully using both IDE's 1.0.5 and 1.5.7
But after compiling my code with 1.5.7, it wasn't running properly and would reset itself - (but just before resetting I could see [with Serial.println() statements] that very weird things were happening (like variables had unexpected values in them)) It seemed almost as if a pointer was pointing into invalid space, or the code was jumping to somewhere it shouldn't. It's very hard to debug stuff like that! But I SEEMED to narrow it down to something:
If I instantiate my class using the "new" keyword (and "delete") it works fine, but using the standard/accepted way to instantiate a class, all these weird things happen. Here the specific code I'm changing:
Original code (broken at runtime, using 1.5.7 IDE):
SetSeqPixels handSsp(strip, startPixelNum, 1, handSize[clkHand], 0, 0, 0, DESTRUCTIVE, CW, NONANIMATED, NOCLEAR, NOGRADIATE, GRADIATE_LASTPIXEL_LASTCOLOR, numColorsInSeries, colorSeriesArr);
handSsp.exec(NOSHOWSTRIP);
New code (works at runtime, using 1.5.7 IDE):
SetSeqPixels *handSsp = new SetSeqPixels(strip, startPixelNum, 1, handSize[clkHand], 0, 0, 0, DESTRUCTIVE, CW, NONANIMATED, NOCLEAR, NOGRADIATE, GRADIATE_LASTPIXEL_LASTCOLOR, numColorsInSeries, colorSeriesArr);
handSsp->exec(NOSHOWSTRIP);
delete(handSsp);
Also, for the record, this code is also broken at runtime, using 1.5.7 IDE (same "weird" problems, followed by reboot):
SetSeqPixels handSsp = SetSeqPixels(strip, startPixelNum, 1, handSize[clkHand], 0, 0, 0, DESTRUCTIVE, CW, NONANIMATED, NOCLEAR, NOGRADIATE, GRADIATE_LASTPIXEL_LASTCOLOR, numColorsInSeries, colorSeriesArr);
handSsp.exec(NOSHOWSTRIP);
Remember, all of my code compiles just fine. It's just during runtime that the different ways of instantiating my class is mattering.
I have a hunch it probably has something to do with the way I made my class. Maybe I got away with something that compiling with IDE 1.0.5 was ok with, but compiling with IDE 1.5.7 causes these weird problems....
Here's the code for the "SetSeqPixels.h" class:
#ifndef SETSEQPIXELS_H
#define SETSEQPIXELS_H
#include <Arduino.h>
#include "LightShowCmd.h"
#include "StandardCplusplus.h"
#include "serstream"
using namespace std;
class SetSeqPixels : public LightShowCmd {
private:
byte currPixelNum;
public:
SetSeqPixels();
SetSeqPixels(Adafruit_NeoPixel* strip,
byte startPixelNum,
byte numPixelsEachColor,
byte colorSeriesNumIter,
byte numPixelsToSkip,
word animDelay,
word pauseAfter,
// boolBits
bool destructive,
bool direction,
bool isAnim,
bool clearStripBefore,
bool gradiate,
bool gradiateLastPixelFirstColor,
byte numColorsInSeries,
PixelColor *colorSeriesArr);
SetSeqPixels(Adafruit_NeoPixel* strip, byte* stripCmdArray);
void init(Adafruit_NeoPixel* strip,
byte startPixelNum,
byte numPixelsEachColor,
byte colorSeriesNumIter,
byte numPixelsToSkip,
word animDelay,
word pauseAfter,
// boolBits
bool destructive,
bool direction,
bool isAnim,
bool clearStripBefore,
bool gradiate,
bool gradiateLastPixelFirstColor,
byte numColorsInSeries,
PixelColor *colorSeriesArr);
void step(boolean isShowStrip);
void reset();
int getCurrPixelColor();
};
#endif // SETSEQPIXELS_H
And the "LightShowCmd.h" base class from which "SetSeqPixels" derives itself from:
#ifndef LIGHTSHOWCMD_H
#define LIGHTSHOWCMD_H
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "PixelColor.h"
#include "Gradient.h"
#include "StandardCplusplus.h"
#include "serstream"
using namespace std;
#include "AllDefs.h"
class LightShowCmd {
protected:
// ======================
// === Cmd Parameters ===
// ======================
byte cmdType;
Adafruit_NeoPixel* strip;
byte startPixelNum;
byte endPixelNum;
byte numSections;
byte numPixelsEachColor;
byte colorSeriesNumIter;
byte numPixelsToSkip;
word numIter;
unsigned long animDelay;
word pauseAfter;
// boolBits
bool destructive;
bool direction;
bool wrap;
bool isAnim;
bool clearStripBefore;
bool gradiate;
bool gradiateLastPixelFirstColor;
byte numColorsInSeries;
PixelColor colorSeriesArr[7]; // up to MAX 7 different color series. (Should be enough for each type of cmd).
// ==============
// === Others ===
// ==============
// Gradiate
MultiGradient multiGradient;
PixelColor currPixelColor;
boolean isFirstTimeAfterFinished;
int cmdFinishedTime;
public:
boolean isPauseMode;
byte currIteration;
//string inOutStr;
LightShowCmd();
boolean isMoreSteps();
virtual void step(boolean isShowStrip) = 0;
void exec(boolean isShowStrip);
static byte fixPixelNum(byte pixelNum);
void showAndWait();
virtual void reset() = 0;
bool bitChecker(byte bit, byte by);
//void clearStrip(Adafruit_NeoPixel* strip);
void clearStrip();
byte getCmdType();
string getCmdTypeStr();
void lscResetCommon();
void lscStepPreCommon();
void lscStepPostCommon(boolean isShowStrip);
bool getIsAnim();
unsigned long getAnimDelay();
void setBoolBitVars(byte boolBits, bool &destructive, bool &direction, bool &wrap, bool &isAnim, bool &clearStripBefore, bool &gradiate, bool &gradiateLastPixelFirstColor);
};
#endif // LIGHTSHOWCMD_H
Another "hunch" is that it MAY be related to the "virtual" functions - it's just a hunch because I don't have a very good grasp of those things. But everything else seems to be pretty standard/basic class stuff.
Another interesting observation, that may help shed light (but just makes me more confused):
There are 2 places in my code where there exists the "Original Code" (see above). While debugging I'm making sure I'm calling just one (and not the other). But even the one that I'm not calling (never, ever!) - if I don't change that ALSO to use the "New Code" (see above), the program crashes (& hence reboots). If I change it to the "New Code", (even though I never, ever call it!), the program runs fine.
Also, for the record, I tried to "Nightly Build" of the IDE today (17th September, 2014) and the same issue occurred).
Also, for the record, I've tried this on 2 boards: Arduino Mega 2560 (with CC3000 shield) and the WildFire board. Same issues on both.
Even though my program "seems" to be running ok now, I don't want to use the "new" and "delete" method (because I don't want to have to worry about garbage collections, fragmentation, etc), and I think generally it's not encouraged to use "new" and "delete" for Arduino projects, right?
Does anything stand out to you as the wrong way to do things? Thank you for your thoughts!