Maybe the map is getting corrupted. But I'm getting some real inconsistencies with the following code. I've explained in comments. Basically, there's a QTimer set to singleShot=false, meaning it should fire over and over at every interval milliseconds. Well, I only want one widget to update the special chars. All Gif widgets with the same widget_base (That's the name of the widget in the config file: such as widget_american_flag) use the same special chars, so only one needs to update those special chars. Well, if I allow the program to have all widget_base widgets to update, it runs fine, but if I limit it to one only, the timer for that widget only shoots off once. Really weird bug.
First, where WidgetGif::Start() is called:
template <class T>
void Generic<T>::StartLayout() {
std::string key;
gen(current_layout_);
Error("StartLayout: %s", key.c_str());
emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeBefore();
std::map<std::string, Widget *> widgets = widgets_;
for(std::map<std::string,Widget *>::iterator w = widgets.begin();
w != widgets.end(); w++){
if(current_layout_ != w->second->GetLayoutBase() )
continue;
if( type_ == LCD_TEXT &&
(w->second->GetType() & WIDGET_TYPE_SPECIAL)) {
w->second->SetupChars();
}
w->second->Start();
}
emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeAfter();
std::stringstream strm;
std::string str;
strm << current_layout_ << ".timeout";
strm >> str;
Json::Value *timeout = CFG_Fetch(CFG_Get_Root(), str,
new Json::Value(layout_timeout_));
timer_->start(timeout->asInt());
Error("timeout: %d", timeout->asInt());
delete timeout;
}
template <class T>
void Generic<T>::StartLayout() {
std::string key;
gen(current_layout_);
Error("StartLayout: %s", key.c_str());
emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeBefore();
std::map<std::string, Widget *> widgets = widgets_;
for(std::map<std::string,Widget *>::iterator w = widgets.begin();
w != widgets.end(); w++){
if(current_layout_ != w->second->GetLayoutBase() )
continue;
if( type_ == LCD_TEXT &&
(w->second->GetType() & WIDGET_TYPE_SPECIAL)) {
w->second->SetupChars();
}
w->second->Start();
}
emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeAfter();
std::stringstream strm;
std::string str;
strm << current_layout_ << ".timeout";
strm >> str;
Json::Value *timeout = CFG_Fetch(CFG_Get_Root(), str,
new Json::Value(layout_timeout_));
timer_->start(timeout->asInt());
Error("timeout: %d", timeout->asInt());
delete timeout;
}
To copy to clipboard, switch view to plain text mode
Now WidgetGif::Start()
template <class T>
void WidgetGif<T>::Start() {
if(is_started_)
return;
if(update_->P2INT() < 0)
return;
if(!has_chars_) {
Update(); // This does not crash the program unlike the one call to Update() below.
Error("Not Starting widget: %s", name_.c_str());
return; // If I comment this out, all widgets' timers update fine.
}
Error("Starting widget: %s", name_.c_str());
timer_->start(); // Only shoots off once if only one widget got this far. (widget_american_flag:0 in this case)
//Update(); // Uncommenting this causes a crash.. something about RB_trees related to the map in StartLayout.
is_started_ = true;
}
template <class T>
void WidgetGif<T>::Start() {
if(is_started_)
return;
if(update_->P2INT() < 0)
return;
if(!has_chars_) {
Update(); // This does not crash the program unlike the one call to Update() below.
Error("Not Starting widget: %s", name_.c_str());
return; // If I comment this out, all widgets' timers update fine.
}
Error("Starting widget: %s", name_.c_str());
timer_->start(); // Only shoots off once if only one widget got this far. (widget_american_flag:0 in this case)
//Update(); // Uncommenting this causes a crash.. something about RB_trees related to the map in StartLayout.
is_started_ = true;
}
To copy to clipboard, switch view to plain text mode
Edit: I changed the code a bit and found that one widget (widget_american_flag:0) never fires even when I allow them all to have running timers.
Bookmarks