2525#include < pxr/usd/usdGeom/tokens.h>
2626
2727#include < maya/MFileIO.h>
28+ #include < maya/MGlobal.h>
2829#include < maya/MSceneMessage.h>
2930
3031#include < map>
@@ -57,6 +58,22 @@ struct _OnSceneResetListener : public TfWeakBase
5758 }
5859};
5960
61+ void clearMayaAttributeEditor ()
62+ {
63+ // When a stage is deleted, the attribute editor could still refer to prims
64+ // that were on that stage. If the attribute editor is collapsed, then it
65+ // won't refresh itself and could later on try to access the prim.
66+ //
67+ // This happens when it receives a UFE notification that it thinks is about
68+ // the prim it is showing. This only happens if one re-stage the same file,
69+ // as the UFE notification will contain the same stage name and the same
70+ // prim path.
71+ //
72+ // To avoid crashes, we refresh the attribute editor templates when the
73+ // stages get cleared.
74+ MGlobal::executeCommand (" refreshEditorTemplates" );
75+ }
76+
6077} // anonymous namespace
6178
6279/* static */
@@ -74,6 +91,7 @@ UsdStageCache& UsdMayaStageCache::Get(const bool loadAll)
7491/* static */
7592void UsdMayaStageCache::Clear ()
7693{
94+ clearMayaAttributeEditor ();
7795 Get (true ).Clear ();
7896 Get (false ).Clear ();
7997}
@@ -88,6 +106,8 @@ size_t UsdMayaStageCache::EraseAllStagesWithRootLayerPath(const std::string& lay
88106 return erasedStages;
89107 }
90108
109+ clearMayaAttributeEditor ();
110+
91111 erasedStages += Get (true ).EraseAll (rootLayer);
92112 erasedStages += Get (false ).EraseAll (rootLayer);
93113
0 commit comments