RuntimeError: 2 : InternalValidationError : found when attempting to access a selectedItem's index

RuntimeError: 2 : InternalValidationError : found when attempting to access a selectedItem's index

perryK67ZX
Contributor Contributor
756 Views
1 Reply
Message 1 of 2

RuntimeError: 2 : InternalValidationError : found when attempting to access a selectedItem's index

perryK67ZX
Contributor
Contributor

My plugin has a dropdown whose options depend on the value of another input. I have a top-level handler that listens to all changes, and computes any changes necessary (such as updating the dropdown's items).

The code to reset the dropdown looks like the following:

dropdown.listItems.add(replacement_text, True) # To get rid of the previously-selected option's text.
dropdown.listItems.clear()
for option in new_options:
    dropdown.listItems.add(option, False)

 

When I later change the dropdown's selection in the UI, I get the following error. `item` here is obtained from `dropdown.selectedItem`, first checking to make sure that it is not None:

  File "/Users/perry/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/ManufacturingSustainabilityInsights/commands/mainDialog/process_picker.py", line 66, in value
    futil.log(f"{item.index}")
                 ^^^^^^^^^^
  File "/Users/perry/Library/Application Support/Autodesk/webdeploy/production/888e96fb45af0b2b166284da26f51796edcd6a6b/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/core.py", line 11306, in _get_index
    return _core.ListItem__get_index(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 2 : InternalValidationError : found


Furthermore, Fusion has been crashing frequently while testing. It seems nondeterministic at times, but one way I've been able to consistently reproduce it is by adding the following snippet to my dropdown-clearing code:

if dropdown.selectedItem is not None:
    dropdown.selectedItem.isSelected = False

 
One more curious thing: It seems my handler that handles UI updates in being called twice when I select something in the dropdown. The first time succeeds, the second time triggers the error.

My current thoughts:
1. Is it possible that the onInputChanged event happens when the code updates an input's value, or is it only for user inputs?
2. Am I just going about things in the wrong way?
3. Are there logs or something that I could check for info when autodesk crashes completely?

Any help or advice would be much appreciated!

0 Likes
757 Views
1 Reply
Reply (1)
Message 2 of 2

perryK67ZX
Contributor
Contributor

I fixed my issue, though I'm still wondering if this is the best approach, or if there are logs to help diagnose the next crash.

For anyone wondering:
A. Yes, onInputChange fires anytime the input changes, including changes from the code. In my case, the code that handled an input change also changed the dropdown. I bet the only reason I didn't have an infinite loop was that I kept getting my validation error.

B. I have no idea why the itemsList.selectedItem returned an item that could cause a crash instead of returning None when nothing was selected, but as a workaround I was able to guard against this scenario by checking the returned item's isValid property and treating it as if it were None in that case.

If anyone has any further thoughts or context here it would be much appreciated.

0 Likes