Skip to content

Commit

Permalink
Working around a crash while running descructors.
Browse files Browse the repository at this point in the history
fix: #1
  • Loading branch information
sirpalee committed Aug 27, 2018
1 parent 549a0f5 commit 05d867a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/hdmaya/adapters/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MCallbackId>().swap(_callbacks);
}

VtValue HdMayaAdapter::Get(const TfToken& /*key*/) { return {}; };

bool HdMayaAdapter::HasType(const TfToken& typeId) { return false; }
Expand Down
2 changes: 2 additions & 0 deletions src/hdmaya/adapters/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/hdmaya/delegates/sceneDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ HdMayaSceneDelegate::HdMayaSceneDelegate(

HdMayaSceneDelegate::~HdMayaSceneDelegate() {
for (auto callback : _callbacks) { MMessage::removeCallback(callback); }
_MapAdapter<HdMayaAdapter>(
[](HdMayaAdapter* a) {
a->RemoveCallbacks();
},
_shapeAdapters, _lightAdapters, _materialAdapters);
}

void HdMayaSceneDelegate::Populate() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -177,6 +184,7 @@ void HdMayaSceneDelegate::RemoveAdapter(const SdfPath& id) {
if (TfMapLookup(_materialAdapters, id, &materialAdapter) &&
materialAdapter != nullptr) {
materialAdapter->RemovePrim();
adapter->RemoveCallbacks();
_materialAdapters.erase(id);
}
}
Expand Down

0 comments on commit 05d867a

Please sign in to comment.