Maya Python API, checking if MPlug.isDefault() gives fatal error on some of the mplug attributes

Hello everyone!
Stuck with some problem, I’m iterating over all attributes in given node and I’m trying to figure out if it is default values or not, using great function isDefaultValue() from MPlug object,
But. In many cases, this gives me Fatal error, during isDefaultValue() retrieving gives crashes on simple function call.
Maybe someone has met with such a problem before? maybe there is some type of attributes, in which I can not call these function?
Huge thanks in advance!

Thing i founded that fatal error rised during retriving default value in attribute, which have index in attribute path,
for example “pCube1.renderLayerInfo[-1].renderLayerColor” but i do not getting why it return -1 index, why MPlug returns negative one as index?

Do you have a reproducible of sorts?

If it involves indicies, it sounds like it isn’t the checking of a default attribute that’s the issue, but one of indexing into a non-existing attribute and making any sort of query about it. That could quite reasonably put Maya into a coma.

1 Like

Thank’s you for your reply!
From the investigation and tests i did on last day,
I found out that it crashes if MPlug have negative indexes in its name
when I ignore such nodes → problem goes away
it looks like a crash happens because it is trying to query default value from wrong\incorrect objects,
but I does not understand why there is can be negative indexes.

Reproducable example with simple cube
if you wan’t to recreate crash comment code with if “-1”
(be careful, Maya will give instant fatal):

import maya.OpenMaya as OpenMaya
import maya.cmds as cmds

def makeDependNode(node_name):
    if node_name:
        selList = OpenMaya.MSelectionList()
        selList.add(node_name)
        node = OpenMaya.MObject()
        selList.getDependNode(0, node)
        return node

# create cube
cube_transform_name = cmds.polyCube()[0]

# get MFnDependencyNode for cube
cube_mobj = makeDependNode(cube_transform_name)
mfn_dependency_node = OpenMaya.MFnDependencyNode(cube_mobj)
attribute_count = mfn_dependency_node.attributeCount()

for i in range(attribute_count):
    # get MPlug object
    attr_mobj = mfn_dependency_node.attribute(i)
    mplug = OpenMaya.MPlug(cube_mobj, attr_mobj)
    plug_name = mplug.name()
    # if you will comment next "if" and try to query isDefaultValue() on each plug, then maya will crash
    if "-1" not in plug_name:
        print("is_default:",mplug.isDefaultValue())