Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception in _pluginLoaded #441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zewt
Copy link

@zewt zewt commented Apr 19, 2021

An exception is raised if a module was loaded during scene load, and something later attempts to load the module again in the future. For example, if a scene requires stereoCamera, and you then open the Create > Cameras menu, the menu will loadModule -qt 1 "stereoCamera.mll" each time it's opened. Each time will raise an exception:

// Error: file: C:/Program Files/Autodesk/Maya2022/scripts/startup/ModCreateMenu.mel line 1041: (kInvalidParameter): No element at given index

Traceback (most recent call last):

File "C:\Users\glenn\AppData\Roaming\Python\Python37\site-packages\pymel\core_init_.py", line 213, in _pluginLoaded

api.MEventMessage.removeCallback(_pluginData[pluginName]['callbackId'])

RuntimeError: (kInvalidParameter): No element at given index //

// Warning: file: C:/Program Files/Autodesk/Maya2022/scripts/startup/ModCreateMenu.mel line 1041: Python callback failed //

This happens in 2020 and 2022. In 2020 it only happened if loadPlugin's -qt (quiet) argument was 0. In 2022 it happens even if it's true, which is why the Create > Cameras menu is triggering it.

This fixes two parts:

  • pymel.core._pluginLoaded's addPluginPyNodes removes the callback, but it leaves callbackId in place, so the later MEventMessage.removeCallback raises an exception when it tries to remove a callback that was already removed.
  • MSceneMessage.kAfterPluginLoad now has three arguments in 2022 instead of two. This part is strange:
    In 2020, the arguments were [pluginPath, pluginFilename].
    In 2022, the arguments are [pluginPath, pluginName, pluginFilename], with the extra pluginName (name without extension) in between.
    In both versions, pluginFilename is "" if the plugin was already loaded (it wasn't actually just loaded), and loadPlugin was called with -qt 1. The new pluginName argument doesn't do this. This is why this only happened in 2020 with -qt 0 (with -qt 1 then the "if not pluginName" check would short-circuit), and why it always happens in 2022 (pluginName is never empty).

This does mean that loadPlugin -qt 0 will still re-process the plugin load unnecessarily and -qt 1 won't. This could probably be avoided by stopping if _pluginData[pluginName] already exists, but I haven't done that here.

(This callback change seems to be undocumented, I'll file a bug. It also feels like a bug that the pluginName argument changes depending on the -qt flag in the first place...)

Tested in Maya 2020 and 2022.

zewt added 2 commits April 18, 2021 22:00
MSceneMessage.kAfterPluginLoad now has three arguments instead of two, and the third argument is
what the second argument used to be.

Fixes the "if not pluginName" short circuit below, so we don't waste time initializing
plugins that we already know about.
This fixes the "Make sure there are no registered callbacks" logic above.  Previously
this could run the callback, unregister it, and then if _pluginLoaded was called again
MEventMessage.removeCallback would raise an exception because it didn't know the
callback was already unregistered.
@cc2-d-patrut
Copy link

I can confirm this issue happening, causing us to first query whether the plugin is loaded to avoid the exception.
Would it be possible to get this pull request accepted?

@zewt
Copy link
Author

zewt commented Nov 25, 2022

Or, you know, any response at all...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants