AnimalLogic / AL_USDMaya

This repo is no longer updated. Please see https://github.com/Autodesk/maya-usd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selecting the same prim twice and clearing the selection crashes AL_USDMaya

sirpalee opened this issue · comments

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)