Skip to content

Commit 667844c

Browse files
Fix corrupted marker/attribute string values
From investigation, it seems that the issue probably stems from the change to GCC 11.2 used on Linux only, or perhaps an internal change to the Maya API, allowing "return value optimisation" or something like that. The issue was that the internal data inside the MString returned from the 'Marker::getLongNodeName()' and 'Attr::getLongName()' method was deallocated, but the object was on the stack, with a dangling pointer. When `MString::asChar()` was called, the pointer pointed to deallocated "random" memory which interpeted the "random" memory as bad characters. The issue was fixed by: 1) Creating temporary MString variable that would hold the data until we could call '.asChar()'. 2) Slightly adjust the ' Marker::getLongNodeName()' to remove unneeded names (probably has no real affect on the code, just some clean up). GitHub issue #273.
1 parent bc5cf73 commit 667844c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/mmSolver/adjust/adjust_results.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -692,29 +692,33 @@ struct SolverObjectUsageResult {
692692
for (MarkerPtrListCIt mit = usedMarkerList.cbegin();
693693
mit != usedMarkerList.cend(); ++mit) {
694694
MarkerPtr marker = *mit;
695-
auto marker_name_char = marker->getLongNodeName().asChar();
696-
Self::markers_used.insert(marker_name_char);
695+
auto marker_name = marker->getLongNodeName();
696+
auto marker_name_char = marker_name.asChar();
697+
Self::markers_used.insert(std::string(marker_name_char));
697698
}
698699

699700
for (MarkerPtrListCIt mit = unusedMarkerList.cbegin();
700701
mit != unusedMarkerList.cend(); ++mit) {
701702
MarkerPtr marker = *mit;
702-
auto marker_name_char = marker->getLongNodeName().asChar();
703-
Self::markers_unused.insert(marker_name_char);
703+
auto marker_name = marker->getLongNodeName();
704+
auto marker_name_char = marker_name.asChar();
705+
Self::markers_unused.insert(std::string(marker_name_char));
704706
}
705707

706708
for (AttrPtrListCIt ait = usedAttrList.cbegin();
707709
ait != usedAttrList.cend(); ++ait) {
708710
AttrPtr attr = *ait;
709-
auto attr_name_char = attr->getLongName().asChar();
710-
Self::attributes_used.insert(attr_name_char);
711+
auto attr_name = attr->getLongName();
712+
auto attr_name_char = attr_name.asChar();
713+
Self::attributes_used.insert(std::string(attr_name_char));
711714
}
712715

713716
for (AttrPtrListCIt ait = unusedAttrList.cbegin();
714717
ait != unusedAttrList.cend(); ++ait) {
715718
AttrPtr attr = *ait;
716-
auto attr_name_char = attr->getLongName().asChar();
717-
Self::attributes_unused.insert(attr_name_char);
719+
auto attr_name = attr->getLongName();
720+
auto attr_name_char = attr_name.asChar();
721+
Self::attributes_unused.insert(std::string(attr_name_char));
718722
}
719723
}
720724

src/mmSolver/mayahelper/maya_marker.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,14 @@ MStatus Marker::getWeight(double &value, const MTime &time,
242242
}
243243

244244
MString Marker::getLongNodeName() {
245-
MString result;
246-
MStatus status;
247-
248245
MObject nodeObj = Marker::getObject();
246+
249247
MDagPath nodeDagPath;
250-
status = MDagPath::getAPathTo(nodeObj, nodeDagPath);
248+
MStatus status = MDagPath::getAPathTo(nodeObj, nodeDagPath);
251249
CHECK_MSTATUS(status);
252250

253-
MString nodeName = nodeDagPath.fullPathName(&status);
251+
MString result = nodeDagPath.fullPathName(&status);
254252
CHECK_MSTATUS(status);
255253

256-
return nodeName;
254+
return result;
257255
}

0 commit comments

Comments
 (0)