shared_ptr<ofxLabel> and ofParameter < string > question

Hi All,

I had this code (ofx 0.9.3, Ubuntu 14.04):

ofApp.h

shared_ptr<ofxFloatSlider> prepProgressBar;
ofParameter<float> prepProgressBarParam;
shared_ptr<ofxLabel> prepProgressBarLabel;
ofParameter<string> prepProgressBarLabelParam;

ofApp.cpp

on setup()

prepProgressBarParam = 0.0f;
prepProgressBar = make_shared<ofxFloatSlider>();
prepProgressBar->setup(prepProgressBarParam);
prepProgressBar->setSize(config->recordingUIHeight*3, (config->recordingUIHeight-titleHeight)*0.33f);
prepProgressBarLabel = make_shared<ofxLabel>();
prepProgressBarLabel->setup(prepProgressBarLabelParam);
prepProgressBarLabel->setSize(config->recordingUIHeight*3, titleHeight);
prepProgressBar->unregisterMouseEvents();

on update()

std::thread([=]() {
    auto start = std::chrono::system_clock::now();
    countDownTime = preparationInputTimeParam;
   recordingToggle->unregisterMouseEvents();
   while(countDownTime>0.0) {
         auto now = std::chrono::system_clock::now();
         std::chrono::duration<double> elapsed_seconds = now-start;
         countDownTime = preparationInputTimeParam-elapsed_seconds.count();
         prepProgressBarParam = countDownTime;
         prepProgressBarLabel->getParameter().cast<string>() = to_string(prepProgressBarParam).substr(0,3) + " sec until recording starts";
   }
  countDown=false;
  recordingToggle->registerMouseEvents(); }).detach();

on draw()

prepProgressBarLabel->draw();

The drawing was throwing an std::bad_alloc error on ofxLabel.cpp line 39:

textMesh = getTextMesh(name + (string)label, b.x + textPadding, b.y + b.height / 2 + 4);

When I changed(string)label to ofToString(label) in the line above I would not the get the error anymore. (Isn’t ofToString the recommended way?)

This all leads to my question: Was I setting up and using ofParameter correctly?

In the end my solution was to change to:

ofApp.h

shared_ptr< ofxFloatSlider > prepProgressBar;
ofParameter< float > prepProgressBarParam;
float prepProgressBarLabelValue;

ofApp.cpp

on update()

auto now = std::chrono::system_clock::now();
std::chrono::duration< double > elapsed_seconds = now-start;
countDownTime = preparationInputTimeParam-elapsed_seconds.count();
prepProgressBarParam = countDownTime;                            
prepProgressBarLabelValue = prepProgressBarParam.get();

on draw()

config->fontNormal.drawString(ofToString( prepProgressBarLabelValue, 1 ) + recordStarts, tempX, tempY+progressBar->getHeight()+prepProgressBar->getHeight()+config->fontNormal.getLineHeight()*2 );

Thanks!