fix(color): Deleting empty label caused EM/Hang (#2392)

* If deleting a label, don't check size

* If rename to blank, do nothing
This commit is contained in:
Cliff
2022-09-28 18:19:59 +10:00
committed by GitHub
parent 6fd69f8053
commit ac091b779d
2 changed files with 20 additions and 14 deletions
+2
View File
@@ -776,6 +776,7 @@ void ModelLabelsWindow::buildBody(FormWindow *window)
strncpy(tmpLabel, oldLabel.c_str(), LABEL_LENGTH); strncpy(tmpLabel, oldLabel.c_str(), LABEL_LENGTH);
tmpLabel[LABEL_LENGTH] = '\0'; tmpLabel[LABEL_LENGTH] = '\0';
new LabelDialog(this, tmpLabel, [=](std::string newLabel) { new LabelDialog(this, tmpLabel, [=](std::string newLabel) {
if(newLabel.size() > 0) {
auto rndialog = auto rndialog =
new ProgressDialog(this, STR_RENAME_LABEL, [=]() {}); new ProgressDialog(this, STR_RENAME_LABEL, [=]() {});
modelslabels.renameLabel( modelslabels.renameLabel(
@@ -785,6 +786,7 @@ void ModelLabelsWindow::buildBody(FormWindow *window)
auto labels = getLabels(); auto labels = getLabels();
lblselector->setNames(labels); lblselector->setNames(labels);
updateFilteredLabels(modelslabels.filteredLabels(), false); updateFilteredLabels(modelslabels.filteredLabels(), false);
}
}); });
return 0; return 0;
}); });
+9 -5
View File
@@ -616,15 +616,19 @@ bool ModelMap::renameLabel(const std::string &from, std::string to,
if (from == "") return true; if (from == "") return true;
DEBUG_TIMER_START(debugTimerYamlScan); DEBUG_TIMER_START(debugTimerYamlScan);
// Limit max label name. TODO: Warn user they entered too long of a string if(to.size() > 0) { // Ignore check if deleting a label, size will be zero
to = to.substr(0, LABEL_LENGTH); to = to.substr(0, LABEL_LENGTH); // Limit max label name. TODO: Warn user they entered too long of a string
removeYAMLChars(to); removeYAMLChars(to); // Remove special chars
if(to.size() == 0) return true; if(to.size() == 0 || from == to) { // Abort rename if no chars left or same
if (progress != nullptr) progress("", 100); // Kill progress dialog
return true;
}
}
ModelData *modeldata = (ModelData *)malloc(sizeof(ModelData)); ModelData *modeldata = (ModelData *)malloc(sizeof(ModelData));
if (!modeldata) { if (!modeldata) {
TRACE("Labels: Out Of Memory"); TRACE("Labels: Out Of Memory");
if (progress != nullptr) progress("", 100); // Kill progress dialog
return true; return true;
} }