From 05d867ae1e0ae966fd662b9e3f0b674f67c5d878 Mon Sep 17 00:00:00 2001 From: Pal Mezei Date: Mon, 27 Aug 2018 18:24:42 +1000 Subject: [PATCH] Working around a crash while running descructors. fix: #1 --- src/hdmaya/adapters/adapter.cpp | 8 +++++++- src/hdmaya/adapters/adapter.h | 2 ++ src/hdmaya/delegates/sceneDelegate.cpp | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/hdmaya/adapters/adapter.cpp b/src/hdmaya/adapters/adapter.cpp index 67dcf17242..78f9f69b26 100644 --- a/src/hdmaya/adapters/adapter.cpp +++ b/src/hdmaya/adapters/adapter.cpp @@ -47,13 +47,19 @@ HdMayaAdapter::HdMayaAdapter( : _node(node), _id(id), _delegate(delegate) {} HdMayaAdapter::~HdMayaAdapter() { - for (auto c : _callbacks) { MMessage::removeCallback(c); } + RemoveCallbacks(); } void HdMayaAdapter::AddCallback(MCallbackId callbackId) { _callbacks.push_back(callbackId); } +void HdMayaAdapter::RemoveCallbacks() { + if (_callbacks.empty()) { return; } + for (auto c : _callbacks) { MMessage::removeCallback(c); } + std::vector().swap(_callbacks); +} + VtValue HdMayaAdapter::Get(const TfToken& /*key*/) { return {}; }; bool HdMayaAdapter::HasType(const TfToken& typeId) { return false; } diff --git a/src/hdmaya/adapters/adapter.h b/src/hdmaya/adapters/adapter.h index fa070d8f1e..10eb016dc7 100644 --- a/src/hdmaya/adapters/adapter.h +++ b/src/hdmaya/adapters/adapter.h @@ -50,6 +50,8 @@ class HdMayaAdapter { HDMAYA_API void AddCallback(MCallbackId callbackId); HDMAYA_API + void RemoveCallbacks(); + HDMAYA_API virtual VtValue Get(const TfToken& key); const MObject& GetNode() { return _node; } HDMAYA_API diff --git a/src/hdmaya/delegates/sceneDelegate.cpp b/src/hdmaya/delegates/sceneDelegate.cpp index 406a933077..9ccdcf99bb 100644 --- a/src/hdmaya/delegates/sceneDelegate.cpp +++ b/src/hdmaya/delegates/sceneDelegate.cpp @@ -134,6 +134,11 @@ HdMayaSceneDelegate::HdMayaSceneDelegate( HdMayaSceneDelegate::~HdMayaSceneDelegate() { for (auto callback : _callbacks) { MMessage::removeCallback(callback); } + _MapAdapter( + [](HdMayaAdapter* a) { + a->RemoveCallbacks(); + }, + _shapeAdapters, _lightAdapters, _materialAdapters); } void HdMayaSceneDelegate::Populate() { @@ -161,6 +166,7 @@ void HdMayaSceneDelegate::RemoveAdapter(const SdfPath& id) { HdMayaShapeAdapterPtr adapter; if (TfMapLookup(_shapeAdapters, id, &adapter) && adapter != nullptr) { adapter->RemovePrim(); + adapter->RemoveCallbacks(); _shapeAdapters.erase(id); return; } @@ -169,6 +175,7 @@ void HdMayaSceneDelegate::RemoveAdapter(const SdfPath& id) { if (TfMapLookup(_lightAdapters, id, &lightAdapter) && lightAdapter != nullptr) { lightAdapter->RemovePrim(); + adapter->RemoveCallbacks(); _lightAdapters.erase(id); return; } @@ -177,6 +184,7 @@ void HdMayaSceneDelegate::RemoveAdapter(const SdfPath& id) { if (TfMapLookup(_materialAdapters, id, &materialAdapter) && materialAdapter != nullptr) { materialAdapter->RemovePrim(); + adapter->RemoveCallbacks(); _materialAdapters.erase(id); } }