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

[MAYA-112601] Selection highlighting in viewport2 via UFE (v1) crash #1169

Closed
eddiehoyle opened this issue Feb 10, 2021 · 8 comments
Closed
Assignees
Labels
bug Something isn't working reproduced Issue has been reproduced

Comments

@eddiehoyle
Copy link

eddiehoyle commented Feb 10, 2021

Describe the bug
Viewport2 does not draw highlights on prims when programmatically selected via UFE (v1) API. If you switch move tools afterwards to translate, rotate, or scale, Maya crashes.

No stack trace, sorry. Internal network restrictions, etc.

This is the line where the crash occurs: UsdTransform3dHandler.cpp#L46

Ufe::Transform3d::Ptr UsdTransform3dHandler::transform3d(const Ufe::SceneItem::Ptr& item) const
{
    UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
#if !defined(NDEBUG)
    assert(usdItem);
#endif

Steps to reproduce

  • Import a USD stage containing any UsdGeomImageable prim that can be drawn in Viewport2 and attempt to programmatically select it using the UFE (v1) Python API.
  • UFE selection will appear valid on inspection, but no selection highlighting will be drawn in viewport.
  • Changing move tools after modifying UFE selection will cause Maya to crash.

Repro snippet (untested, manually copied and typed out):

import ufe
import mayaUsd.ufe
import mayaUsd.lib
from maya import cmds
from pxr import Usd, UsdGeom

# Create simple stage with Cube prim
stage = Usd.Stage.CreateInMemory()
UsdGeom.Cube.Define(stage, "/cube")
stage.Export("/tmp/cube.usda")

# Create new Maya scene, load plugin, import stage, clear selection
cmds.file(new=True, force=True)
cmds.loadPlugin("mayaUsdPlugin", quiet=True)
proxy_shape = cmds.createNode("mayaUsdProxyShape")
cmds.setAttr("{}.filePath".format(proxy_shape), "/tmp/cube.usda", type="string")
cmds.select(clear=True)

# Construct UFE item for cube
maya_segment = ufe.PathSegment("|world{}".format(cmds.ls(proxy_shape, long=True)[0]), mayaUsd.ufe.getMayaRunTimeId(), "|")
usd_segment = ufe.PathSegment("/cube", mayaUsd.ufe.getUsdRunTimeId(), "/")
item = ufe.SceneItem(ufe.Path([maya_segment, usd_segment]))

# Create new selection for cube
sel = ufe.Selection()
sel.append(item)

# Modify global selection
gsel = ufe.GlobalSelection.get()
gsel.clear()
assert gsel.empty()
gsel.replaceWith(sel)
assert not gsel.empty()

# Assert selection contains valid data
selected_item = list(gsel).pop()
selected_prim = mayaUsd.ufe.ufePathToPrim(",".join(filter(None, map(str, item.path().segments))))
assert selected_prim
assert selected_prim.GetStage() == mayaUsd.lib.getStage(str(maya_segment))

# Viewport should display cube as unselected
# Changing move tools will cause a crash here
# ...

Expected behavior
Maya should draw the selected prim as highlighted, and ideally not crash when changing between move tools.

Specs:

  • centos-7
  • maya-2020.3
  • maya_usd-0.7
  • usd-0.20.11
@eddiehoyle eddiehoyle added the bug Something isn't working label Feb 10, 2021
@eddiehoyle
Copy link
Author

I wonder if PR #1050 fixes this? With this I could drop the "|world" prefix from my Python code and UFE v1 might avoid the failed assertion. It looks like it just missed the 0.7.0 release too. Dang.

@santosd
Copy link
Collaborator

santosd commented Jun 28, 2021

Tested this using the latest 2020.4 release with the 0.10.0 release of Maya USD and was able to reproduce the crash. @eddiehoyle I am wondering that if with the changes in PR#1050 you were able to workaround the the crash?

I was not able to reproduce this issue in UFE v2 using Maya 2022.

@santosd santosd added the reproduced Issue has been reproduced label Jun 28, 2021
@eddiehoyle
Copy link
Author

Hey @santosd, thanks for taking a look. #1050 didn't end up fixing this for me sadly. My solution was to disable API selection via tools in Maya 2020 and putting this in the "I hope this is fixed in Maya 2022" pile. With that said...

I was not able to reproduce this issue in UFE v2 using Maya 2022.

That's great! Unfortunately I don't have access to Maya 2022, and adopting this version on a show is even further away. Do you think it could be possible to have this fixed in UFE v1 for those of us still working with Maya 2020?

@wtelford
Copy link
Contributor

@santosd Can you log this internally?

@santosd santosd changed the title Selection highlighting in viewport2 via UFE (v1) crash [MAYA-112601] Selection highlighting in viewport2 via UFE (v1) crash Jun 29, 2021
@santosd
Copy link
Collaborator

santosd commented Jun 29, 2021

Logged internally as MAYA-112601 so that we can take a closer look at this issue.

@ppt-adsk
Copy link
Collaborator

Hi @eddiehoyle, thanks for reporting and identifying the cause of the crash, fixed in
#1596
This is not 2020 specific; it is now fixed for all versions of Maya.

The more interesting point is that your test code isn't doing what you might expect it to do, and the core source of the problem is the line that creates the scene item directly out of the Python class constructor:
item = ufe.SceneItem(ufe.Path([maya_segment, usd_segment]))
This certainly is valid syntax, and nothing prevents you from creating a scene item this way --- except the result is a scene item that is not a USD scene item. It is a UFE Python base class scene item, in no way created by or associated with the maya-usd plugin, a kind of hollow shell of a scene item, which won't do you any good at all... It's got a Ufe::Path, but that's about it.

If you replace that line with a call that does go into the maya-usd plugin:
item = ufe.Hierarchy.createItem(ufe.Path([maya_segment, usd_segment]))
then you'll be a lot happier. You will get a USD scene item, selection highlighting will work, TRS manipulators will work, Maya commands that are UFE-enabled (e.g. move, rotate, scale, rename, duplicate, delete, etc.) will start working.

Hope this helps. Cheers!

@eddiehoyle
Copy link
Author

Ahh, this whole time I thought all ufe.SceneItems were created equal and UFE managed the mapping to their underlying runtime objects via path segments. Now I see.

You will get a USD scene item, selection highlighting will work, TRS manipulators will work, Maya commands that are UFE-enabled (e.g. move, rotate, scale, rename, duplicate, delete, etc.) will start working.

highlighting

I can confirm switching to ufe.Hierarchy.createItem no longer causes a crash on my end, and everything works as intended now. Thanks for the explanation and fix!

@santosg87
Copy link
Collaborator

marking this one as closed, based on the conversation above. :) if this is still a problem, feel free to re-open it @eddiehoyle :)

@neilh-adsk neilh-adsk moved this to Done in maya-usd Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduced Issue has been reproduced
Projects
Archived in project
Development

No branches or pull requests

5 participants