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

Selection change functors now take scene index as argument. #26

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,37 +941,38 @@ void MtohRenderOverride::SelectionChanged(
// reading the Maya selection must be done from the Maya selection
// changed callback, not the UFE selection changed callback.
using SnOp = Ufe::SelectionCompositeNotification::Op;
static auto appendSn = [this](const SnOp& op) {
_selectionSceneIndex->AddSelection(op.item->path());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Capturing the selection scene index once, on creation of the static functor, is incorrect, as the selection scene index is destroyed and re-created. We were therefore calling member functions on a destroyed object, causing crashes.

using SnSiPtr = Fvp::SelectionSceneIndexRefPtr;
static auto appendSn = [](const SnOp& op, const SnSiPtr& si) {
si->AddSelection(op.item->path());
};
static auto removeSn = [this](const SnOp& op) {
_selectionSceneIndex->RemoveSelection(op.item->path());
static auto removeSn = [](const SnOp& op, const SnSiPtr& si) {
si->RemoveSelection(op.item->path());
};
// FLOW_VIEWPORT_TODO Support selection insert. PPT, 19-Oct-2023
static auto insertSn = [](const SnOp&) {
static auto insertSn = [](const SnOp&, const SnSiPtr& si) {
TF_WARN("Insert into selection not supported.");
};
static auto clearSn = [this](const SnOp&) {
_selectionSceneIndex->ClearSelection();
static auto clearSn = [](const SnOp&, const SnSiPtr& si) {
si->ClearSelection();
};
static auto replaceWithSn = [this](const SnOp& op) {
_selectionSceneIndex->ReplaceSelection(*Ufe::GlobalSelection::get());
static auto replaceWithSn = [](const SnOp& op, const SnSiPtr& si) {
si->ReplaceSelection(*Ufe::GlobalSelection::get());
};
static std::function<void(const SnOp&)> changeSn[] = {appendSn, removeSn, insertSn, clearSn, replaceWithSn};
static std::function<void(const SnOp&, const SnSiPtr&)> changeSn[] = {appendSn, removeSn, insertSn, clearSn, replaceWithSn};

if (notification.opType() ==
Ufe::SelectionChanged::SelectionCompositeNotification) {

const auto& compositeNotification = notification.staticCast<Ufe::SelectionCompositeNotification>();

for (const auto& op : compositeNotification) {
changeSn[op.opType](op);
changeSn[op.opType](op, _selectionSceneIndex);
}
}
else {
SnOp op(notification);

changeSn[op.opType](op);
changeSn[op.opType](op, _selectionSceneIndex);
}


Expand Down