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-123016 catch exceptions during notifications #2358

Merged
merged 2 commits into from
May 17, 2022

Conversation

pierrebai-adsk
Copy link
Collaborator

Exception can be thrown by the notified objects or function. Do not let it out as it will crash Maya as nothing else above catches the exceptions.

Exception can be thrown by the notified objects or function. Do not let it out as it will crash Maya as nothing else above catches the exceptions.
@@ -68,6 +68,20 @@ bool isTransformChange(const TfToken& nameToken)
return nameToken == UsdGeomTokens->xformOpOrder || UsdGeomXformOp::IsXformOp(nameToken);
}

// Prevent exception from the notifications from escaping and breaking USD/Maya.
// USD does not wrap its notification in try/catch, so we need to do it ourselves.
template <class RECEIVER> struct SafeNotification
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be just a single templated function, doesn't need to be static, we're in the unnamed namespace already:
template<class R, class N> void notify(const N& n) {
// try / catch stuff
R::notify(n);
}
You can then explicitly specify a single template argument and the second template argument (the type of the function argument) will be deduced by the compiler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good, I thought that if we provided one template type, we had to provide both, that is why I use this trick to split them.

@pierrebai-adsk pierrebai-adsk added the ready-for-merge Development process is finished, PR is ready for merge label May 17, 2022
@seando-adsk seando-adsk merged commit 555dc76 into dev May 17, 2022
@seando-adsk seando-adsk deleted the t_bailp/MAYA-123016/exception-during-notification branch May 17, 2022 19:49
@seando-adsk seando-adsk added the ufe-usd Related to UFE-USD plugin in Maya-Usd label May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge ufe-usd Related to UFE-USD plugin in Maya-Usd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants