Skip to content

Commit 5932ce6

Browse files
authored
--revert markerset subconfig removals; Don't write empty configs to file (#2435)
Removing the markerset subconfigs when they were empty caused memory corruption in certain rare cases, so this is change is being reverted; Instead, a subconfig with no values in its entire subconfig tree (instead of just in its own primary map) will not be written to JSON.
1 parent 0b58d04 commit 5932ce6

File tree

2 files changed

+8
-35
lines changed

2 files changed

+8
-35
lines changed

src/esp/core/Configuration.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ void Configuration::writeSubconfigsToJson(io::JsonGenericValue& jsonObj,
606606
auto cfgIterPair = getSubconfigIterator();
607607
for (auto& cfgIter = cfgIterPair.first; cfgIter != cfgIterPair.second;
608608
++cfgIter) {
609-
// only save if subconfig has entries
610-
if (cfgIter->second->getNumEntries() > 0) {
609+
// only save if subconfig tree has value entries
610+
if (cfgIter->second->getConfigTreeNumValues() > 0) {
611611
// Create Generic value for key, using allocator, to make sure its a copy
612612
// and lives long enough
613613
io::JsonGenericValue name{cfgIter->first.c_str(), allocator};

src/esp/metadata/attributes/MarkerSets.h

+6-33
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ class LinkSet : public esp::core::config::Configuration {
145145
*/
146146
void setMarkerSetPoints(const std::string& markerSetName,
147147
const std::vector<Mn::Vector3>& markerList) {
148-
if (markerList.size() == 0) {
149-
removeMarkerSet(markerSetName);
150-
} else {
151-
editMarkerSet(markerSetName)->setAllPoints(markerList);
152-
}
148+
editMarkerSet(markerSetName)->setAllPoints(markerList);
153149
}
154150

155151
/**
@@ -325,12 +321,7 @@ class TaskSet : public esp::core::config::Configuration {
325321
void setLinkMarkerSetPoints(const std::string& linkSetName,
326322
const std::string& markerSetName,
327323
const std::vector<Mn::Vector3>& markerList) {
328-
auto linkSet = editLinkSet(linkSetName);
329-
linkSet->setMarkerSetPoints(markerSetName, markerList);
330-
// The above may result in the link set being empty. If so remove it.
331-
if (linkSet->getNumMarkerSets() == 0) {
332-
removeLinkSet(linkSetName);
333-
}
324+
editLinkSet(linkSetName)->setMarkerSetPoints(markerSetName, markerList);
334325
}
335326

336327
/**
@@ -345,12 +336,7 @@ class TaskSet : public esp::core::config::Configuration {
345336
const std::string& linkSetName,
346337
const std::unordered_map<std::string, std::vector<Mn::Vector3>>&
347338
markers) {
348-
auto linkSet = editLinkSet(linkSetName);
349-
linkSet->setAllMarkerPoints(markers);
350-
// The above may result in the link set being empty. If so remove it.
351-
if (linkSet->getNumMarkerSets() == 0) {
352-
removeLinkSet(linkSetName);
353-
}
339+
editLinkSet(linkSetName)->setAllMarkerPoints(markers);
354340
}
355341

356342
/**
@@ -585,12 +571,8 @@ class MarkerSets : public esp::core::config::Configuration {
585571
const std::string& linkSetName,
586572
const std::string& markerSetName,
587573
const std::vector<Mn::Vector3>& markerList) {
588-
auto taskSetPtr = editTaskSet(taskSetName);
589-
taskSetPtr->setLinkMarkerSetPoints(linkSetName, markerSetName, markerList);
590-
// After this process, the taskset might be empty, if so, delete it.
591-
if (taskSetPtr->getNumLinkSets() == 0) {
592-
removeTaskSet(taskSetName);
593-
}
574+
editTaskSet(taskSetName)
575+
->setLinkMarkerSetPoints(linkSetName, markerSetName, markerList);
594576
}
595577

596578
/**
@@ -607,12 +589,7 @@ class MarkerSets : public esp::core::config::Configuration {
607589
const std::string& linkSetName,
608590
const std::unordered_map<std::string, std::vector<Mn::Vector3>>&
609591
markerMap) {
610-
auto taskSetPtr = editTaskSet(taskSetName);
611-
taskSetPtr->setLinkSetPoints(linkSetName, markerMap);
612-
// After this process, the taskset might be empty, if so, delete it.
613-
if (taskSetPtr->getNumLinkSets() == 0) {
614-
removeTaskSet(taskSetName);
615-
}
592+
editTaskSet(taskSetName)->setLinkSetPoints(linkSetName, markerMap);
616593
}
617594

618595
/**
@@ -632,10 +609,6 @@ class MarkerSets : public esp::core::config::Configuration {
632609
for (const auto& markers : markerMap) {
633610
taskSetPtr->setLinkSetPoints(markers.first, markers.second);
634611
}
635-
// After this process, the taskset might be empty, if so, delete it.
636-
if (taskSetPtr->getNumLinkSets() == 0) {
637-
removeTaskSet(taskSetName);
638-
}
639612
}
640613

641614
/**

0 commit comments

Comments
 (0)