I’d like to be able to apply an Sdf.NamespaceEdit
inside a variant edit target, but it keeps crashing on me.
from pxr import Usd, Sdf
# Create a stage with a root xform
stage = Usd.Stage.CreateInMemory()
prim = stage.DefinePrim("/root", "Xform")
# Add variant set
variant_sets = prim.GetVariantSets()
variant_set = variant_sets.AddVariantSet("model")
# Add some variants
variant_set.AddVariant("main")
variant_set.AddVariant("damaged")
variant_set.AddVariant("ice")
# Set the variant selection
variant_set.SetVariantSelection("main")
edit_target = variant_set.GetVariantEditTarget()
stage.SetEditTarget(edit_target)
child = stage.DefinePrim("/root/child", "Xform")
spec = next(iter(child.GetPrimStack())) # there is only one prim spec in this case, it's in the variant set
assert spec.path == '/root{model=main}child'
# Rename, keep parent
edit = Sdf.NamespaceEdit.Rename(
spec.path,
"new_name"
)
layer = spec.layer
batch_edit = Sdf.BatchNamespaceEdit()
batch_edit.Add(edit)
layer.Apply(batch_edit)
child = stage.GetPrimAtPath("/root/new_name")
assert child, "Renamed child must exist"
assert not stage.GetPrimAtPath("/root/child"), "Old prim name must not exist"
# However, now accessing the prim stack for the renamed prim crashes
prim_stack = child.GetPrimStack() # CRASH
Am I missing something obvious?
Running it in Maya provides me this crash log:
//=====================================================
Maya Crash Report
//=====================================================
Exception code: C0000005: ACCESS_VIOLATION - illegal read at address 0x00000000
Fault address: D502A5FF in C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\usd_pcp.dll
0001:001895FF Logical offset (see .map file for location)
Call stack:
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\usd_usd.dll (-exported-)
Location: usd_usd.dllpxrInternal_v0_22__pxrReserved__::UsdAttributeQuery::_Get<pxrInternal_v0_22__pxrReserved__::VtArray<pxrInternal_v0_22__pxrReserved__::GfVec4d> > + 79B164 bytes
Decl: private: bool __cdecl pxrInternal_v0_22__pxrReserved__::UsdAttributeQuery::_Get<class pxrInternal_v0_22__pxrReserved__::VtArray<class pxrInternal_v0_22__pxrReserved__::GfVec4d> >(class pxrInternal_v0_22__pxrReserved__::VtArray<class pxrInternal_v0_22__px
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\usd_usd.dll (-exported-)
Location: usd_usd.dllpxrInternal_v0_22__pxrReserved__::UsdAttributeQuery::_Get<pxrInternal_v0_22__pxrReserved__::VtArray<pxrInternal_v0_22__pxrReserved__::GfVec4d> > + 488E40 bytes
Decl: private: bool __cdecl pxrInternal_v0_22__pxrReserved__::UsdAttributeQuery::_Get<class pxrInternal_v0_22__pxrReserved__::VtArray<class pxrInternal_v0_22__pxrReserved__::GfVec4d> >(class pxrInternal_v0_22__pxrReserved__::VtArray<class pxrInternal_v0_22__px
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\python\pxr\Usd\_usd.pyd (-exported-)
Location: _usd.pydPyInit_libusd + 1910DA bytes
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::objects::function::call + 2D3 bytes
Decl: public: struct _object * __ptr64 __cdecl boost::python::objects::function::call(struct _object * __ptr64,struct _object * __ptr64)const __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::objects::static_data + 2AA bytes
Decl: struct _object * __ptr64 __cdecl boost::python::objects::static_data(void)
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::detail::exception_handler::operator() + 3B bytes
Decl: public: bool __cdecl boost::python::detail::exception_handler::operator()(class boost::function0<void> const & __ptr64)const __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\python\pxr\Tf\_tf.pyd (-exported-)
Location: _tf.pydpxrInternal_v0_22__pxrReserved__::tfTestStaticTokens_StaticTokenType::tfTestStaticTokens_StaticTokenType + 619F0 bytes
Decl: public: __cdecl pxrInternal_v0_22__pxrReserved__::tfTestStaticTokens_StaticTokenType::tfTestStaticTokens_StaticTokenType(void) __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::handle_exception_impl + 47 bytes
Decl: bool __cdecl boost::python::handle_exception_impl(class boost::function0<void>)
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::objects::static_data + 35A bytes
Decl: struct _object * __ptr64 __cdecl boost::python::objects::static_data(void)
Module: C:\Program Files\Autodesk\Maya2024\bin\python310.dll (-exported-)
Location: python310.dll_PyObject_Call + 96 bytes
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\usd_tf.dll (-exported-)
Location: usd_tf.dllpxrInternal_v0_22__pxrReserved__::TfPyEnsureGILUnlockedObj::TfPyEnsureGILUnlockedObj + 13415F bytes
Decl: public: __cdecl pxrInternal_v0_22__pxrReserved__::TfPyEnsureGILUnlockedObj::TfPyEnsureGILUnlockedObj(void) __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::objects::function::call + 2D3 bytes
Decl: public: struct _object * __ptr64 __cdecl boost::python::objects::function::call(struct _object * __ptr64,struct _object * __ptr64)const __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::objects::static_data + 2AA bytes
Decl: struct _object * __ptr64 __cdecl boost::python::objects::static_data(void)
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::detail::exception_handler::operator() + 3B bytes
Decl: public: bool __cdecl boost::python::detail::exception_handler::operator()(class boost::function0<void> const & __ptr64)const __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\python\pxr\Tf\_tf.pyd (-exported-)
Location: _tf.pydpxrInternal_v0_22__pxrReserved__::tfTestStaticTokens_StaticTokenType::tfTestStaticTokens_StaticTokenType + 619F0 bytes
Decl: public: __cdecl pxrInternal_v0_22__pxrReserved__::tfTestStaticTokens_StaticTokenType::tfTestStaticTokens_StaticTokenType(void) __ptr64
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::handle_exception_impl + 47 bytes
Decl: bool __cdecl boost::python::handle_exception_impl(class boost::function0<void>)
Module: C:\Program Files\Autodesk\MayaUSD\Maya2024\0.26.0_202311130904-e634cda\mayausd\USD\lib\boost_python310-vc142-mt-x64-1_76.dll (-exported-)
Location: boost_python310-vc142-mt-x64-1_76.dllboost::python::objects::static_data + 35A bytes
Decl: struct _object * __ptr64 __cdecl boost::python::objects::static_data(void)
It also crashes outside of Maya in Python with usd-core
but I’m not sure how to get such a crash dump there.