AL_USDMaya
AL_USDMaya copied to clipboard
Selecting the same prim twice and clearing the selection crashes AL_USDMaya
The selected prims can stack up in helper.m_paths, then their reference counts are going below zero.
A quick workaround for this problem is to avoid storing the same path twice, but in the long term a second look at the internal reference counting, and avoiding crashing Maya on invalid states is a better option.
diff --git a/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp b/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp
index 4503116..6f8465e 100644
--- a/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp
+++ b/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp
@@ -1040,7 +1040,15 @@ bool ProxyShape::doSelect(SelectionUndoHelper& helper)
}
}
- helper.m_paths.insert(helper.m_paths.end(), helper.m_previousPaths.begin(), helper.m_previousPaths.end());
+ const auto newSize = helper.m_paths.size() + helper.m_previousPaths.size();
+ if (helper.m_paths.capacity() < newSize) {
+ helper.m_paths.reserve(newSize);
+ }
+ for (const auto& path : helper.m_previousPaths) {
+ if (std::find(helper.m_paths.begin(), helper.m_paths.end(), path) == helper.m_paths.end()) {
+ helper.m_paths.push_back(path);
+ }
+ }
uint32_t hasNodesToCreate = 0;
for(auto prim : prims)