Maya 2022 crashes when accessing MIntArray with negative indices

Maya 2022 crashes when accessing MIntArray with negative indices

e_honda
Enthusiast Enthusiast
605 Views
5 Replies
Message 1 of 6

Maya 2022 crashes when accessing MIntArray with negative indices

e_honda
Enthusiast
Enthusiast

Hi there,

I was testing the new Maya 2022 in its Python 3 mode and encountered some problem.

 

I realized that some scripts those worked in earlier version just crashes Maya 2022.

I did a quick research about that and extracted a simple code that can reproduce the error.

 

from maya.api import OpenMaya

# create an OpenMaya.MIntArray object
temp_list = OpenMaya.MIntArray([0,1])
# accessing array's member using negative index crashes Maya 2022 with fatal error
print(temp_list[-1])

 

I'm running Maya 2022.0 in Windows 10.

As a workaround, I'm using a little function to convert negative indices to positive ones.

Is it a problem that occurs just in my environment?

 

Best Regards,

Honda

606 Views
5 Replies
Replies (5)
Message 2 of 6

e_honda
Enthusiast
Enthusiast

Just a quick update.

 

Other OpenMaya's array types also crashes Maya 2022.

It seems that launching Maya 2022 in Python 2 mode avoids the problem.

Maybe there is some problem in the Python 3 version of the Python API 2.0?

 

from maya.api import OpenMaya

temp_list = OpenMaya.MFloatArray([0.0, 1.0])
print(temp_list[-1])

 

from maya.api import OpenMaya

temp_list = OpenMaya.MPointArray([OpenMaya.MPoint(), OpenMaya.MPoint()])
print(temp_list[-1])

 

0 Likes
Message 3 of 6

WindXu
Alumni
Alumni

Thanks for reporting this issue. I can reproduce it with Maya 2022 in Python 3 mode, but not in Python 2 mode. I have logged a bug internally. We will fix it as soon as possible.

 

Thanks again

0 Likes
Message 4 of 6

e_honda
Enthusiast
Enthusiast

Hi WindXu,

 

Hope the bug would be fixed in future updates.

I checked that the OpenMaya.XXXXArray has other problem too, so I'll share here in this thread.

from maya.api import OpenMaya

temp_list = OpenMaya.MIntArray([0,1])

# should raise an IndexError, but returns the memory pointer's value?
print(temp_list[50])

 

For now, I will use a simple function to avoid the error. Maybe not the best solution, but something like below:

from maya.api import OpenMaya


def get_item_at_index(omarray, index):
    """
        function made just to avoid problems when accessing Maya2022's OpenMaya.XXXXXXArray items.
    """
    len_array = len(omarray)
    index = len_array + index if index < 0 else index
    if index < 0:
        raise IndexError('list index out of range')
    elif index >= len_array:
        raise IndexError('list index out of range')
    return omarray[index]


temp_list = OpenMaya.MIntArray([0,1])
print(get_item_at_index(temp_list, -1)

 

Thanks for your attention!

 

Best Regards,

Honda

0 Likes
Message 5 of 6

WindXu
Alumni
Alumni

Yes, I noticed the issue with out of range index too when I did the test yesterday. I also logged it in the same bug. 

 

Thanks

Message 6 of 6

negow
Advocate
Advocate

Thanks for this, I have been experiencing this as well!