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

Accessing JobExportArgs "referenceObjectMode" or "exportRelativeTextures" from Python would cause Maya to crash #3809

Closed
csyshing opened this issue Jun 7, 2024 · 1 comment · Fixed by #3845
Assignees
Labels
bug Something isn't working

Comments

@csyshing
Copy link
Collaborator

csyshing commented Jun 7, 2024

Describe the bug

In our studio pipeline, we have setup export chaser in Python, we recently found that accessing the "referenceObjectMode" argument from Python would cause Python exception, if the exception is not caught, it would cause Maya to crash.

So far we have seen "referenceObjectMode" and "exportRelativeTextures" arguments could cause problem, other arguments are working fine.

Steps to reproduce
Steps to reproduce the behavior:

  1. Launch Maya
  2. Run following code snippet:
# Load Maya USD plugin
from maya import cmds
cmds.loadPlugin('mayaUsdPlugin')

# Define the export chaser in Python (minimum example):
class TestExportChaser(mayaUsd.lib.ExportChaser):
    def __init__(self, factoryContext, *args):
        print(factoryContext)
        print(factoryContext.GetJobArgs())
        try:
            print(factoryContext.GetJobArgs().referenceObjectMode)
        except Exception as exc:
            print(exc)
    def ExportDefault(self):
        return True
    def ExportFrame(self, frame):
        return True
    def PostExport(self):
        return True

# Register the chaser
mayaUsd.lib.ExportChaser.Register(TestExportChaser, 'TestExportChaser')

# Export to USD file to trigger the problem
filePath = '/path/to/export/location.usda'
cmds.file(filePath, force=True, type="USD Export", ea=True,
    options="chaser=[TestExportChaser];defaultUSDFormat=usda;referenceObjectMode=defaultToMesh;")
  1. Maya script editor would have output like this:
<mayaUsd.lib.UsdMayaExportChaserRegistryFactoryContext object at 0x7ff8661d9540>
<mayaUsd.lib.JobExportArgs object at 0x7ff865eec220>
No Python class registered for C++ class pxrInternal_v0_23__pxrReserved__::TfToken
  1. If the try....except.... around print(factoryContext.GetJobArgs().referenceObjectMode) wasn't there, Maya would simply crash.

Expected behavior

Be able to access "referenceObjectMode" without any problem.

Specs (if applicable):

  • OS & version: CentOS 7.8
  • Compiler & version: GCC 6.3
  • Maya version: Maya-2023
  • Maya USD: Official v0.28.0
  • Pixar USD: Official v23.02, v22.05

Additional context

The problem seems to be fact that TfToken was exposed directly but it should behave like a Python string, there is one related comment in USD repo:
PixarAnimationStudios/OpenUSD#1194 (comment)

One of the potential fixes might be changing the way how to expose this "referenceObjectMode" argument and "exportRelativeTextures" argument in Python binding, e.g.:
Changing .def_readonly(....):
https://github.com/Autodesk/maya-usd/blob/v0.28.0/lib/mayaUsd/python/wrapPrimWriter.cpp#L544

.def_readonly("referenceObjectMode", &UsdMayaJobExportArgs::referenceObjectMode)

To be something like:

.add_property(
    "referenceObjectMode",
    make_getter(&UsdMayaJobExportArgs::referenceObjectMode, return_value_policy<return_by_value>()))
@csyshing csyshing added the bug Something isn't working label Jun 7, 2024
@csyshing csyshing changed the title Accessing JobExportArgs "referenceObjectMode" from Python would cause Maya to crash Accessing JobExportArgs "referenceObjectMode" or "exportRelativeTextures" from Python would cause Maya to crash Jun 7, 2024
@seando-adsk
Copy link
Collaborator

@csyshing Sorry for the delay. Would you be able to submit a PR with your fix and a unit test to verify that both these attributes can be properly accessed?

Thanks, Sean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants