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

Fix python 3.9 AL TransactionManager crash #1698

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//
#include "AL/usdmaya/Global.h"

#include "AL/usd/transaction/TransactionManager.h"
#include "AL/usdmaya/DebugCodes.h"
#include "AL/usdmaya/StageCache.h"
#include "AL/usdmaya/nodes/LayerManager.h"
Expand Down Expand Up @@ -201,6 +202,7 @@ AL::event::CallbackId Global::m_postSave;
AL::event::CallbackId Global::m_preRead;
AL::event::CallbackId Global::m_postRead;
AL::event::CallbackId Global::m_fileNew;
AL::event::CallbackId Global::m_mayaExit;
AL::event::CallbackId Global::m_preExport;
AL::event::CallbackId Global::m_postExport;

Expand Down Expand Up @@ -284,6 +286,14 @@ static void onFileNew(void*)
// Puzzled.
UsdUtilsStageCache::Get().Clear();
StageCache::Clear();
AL::usd::transaction::TransactionManager::CloseAll();
}

//----------------------------------------------------------------------------------------------------------------------
static void onMayaExit(void*)
{
TF_DEBUG(ALUSDMAYA_EVENTS).Msg("onMayaExit\n");
onFileNew(nullptr);
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -441,6 +451,7 @@ void Global::onPluginLoad()

auto& manager = AL::maya::event::MayaEventManager::instance();
m_fileNew = manager.registerCallback(onFileNew, "AfterNew", "usdmaya_onFileNew", 0x1000);
m_mayaExit = manager.registerCallback(onMayaExit, "MayaExiting", "usdmaya_onMayaExit", 0x1000);
m_preSave = manager.registerCallback(preFileSave, "BeforeSave", "usdmaya_preFileSave", 0x1000);
m_postSave
= manager.registerCallback(postFileSave, "AfterSave", "usdmaya_postFileSave", 0x1000);
Expand Down
6 changes: 5 additions & 1 deletion plugin/al/lib/AL_USDMaya/AL/usdmaya/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Global
/// callback used to flush the USD caches after a file new
static AL::event::CallbackId fileNew() { return m_fileNew; }

/// callback used to flush the USD caches on exit
static AL::event::CallbackId mayaExit() { return m_mayaExit; }

static void openingFile(bool val);

private:
Expand All @@ -64,7 +67,8 @@ class Global
static AL::event::CallbackId m_postRead; ///< callback executed after opening a maya file -
///< needed to re-hook up the UsdPrims
static AL::event::CallbackId
m_fileNew; ///< callback used to flush the USD caches after a file new
m_fileNew; ///< callback used to flush the USD caches after a file new
static AL::event::CallbackId m_mayaExit; ///< callback used to flush the USD caches on exit
static AL::event::CallbackId
m_preExport; ///< callback prior to exporting the scene (so we can store the session layer)
static AL::event::CallbackId m_postExport; ///< callback after exporting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ bool TransactionManager::Close(const UsdStageWeakPtr& stage, const SdfLayerHandl
return false;
}

//----------------------------------------------------------------------------------------------------------------------
void TransactionManager::CloseAll() { GetManagers().clear(); }

//----------------------------------------------------------------------------------------------------------------------
} // namespace transaction
} // namespace usd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class TransactionManager
AL_USD_TRANSACTION_PUBLIC
static bool Close(const PXR_NS::UsdStageWeakPtr& stage, const PXR_NS::SdfLayerHandle& layer);

/// \brief clears the transaction manager of all active transactions, effectively closing them
/// all. Intended to be used for File->New and on exit.
AL_USD_TRANSACTION_PUBLIC
static void CloseAll();

private:
typedef std::map<PXR_NS::UsdStageWeakPtr, TransactionManager> StageManagerMap;
static StageManagerMap& GetManagers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def setUp(self):
if sys.version_info[0] >= 3:
self.assertItemsEqual = self.assertCountEqual

def tearDown(self):
transaction.TransactionManager.CloseAll()

def _openNoticeHandler(self, notice, stage):
self.assertEqual(stage, self._stage)
self._opened += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def test_InProgress_Stage(self):
self.assertFalse(TransactionManager.InProgress(stageA))
self.assertFalse(TransactionManager.InProgress(stageB))

TransactionManager.CloseAll()

## Test that TransactionManager reports transactions for multiple layers as expected
def test_InProgress_Layer(self):
stage = Usd.Stage.CreateInMemory()
Expand Down Expand Up @@ -67,6 +69,8 @@ def test_InProgress_Layer(self):
self.assertFalse(TransactionManager.InProgress(stage, layerA))
self.assertFalse(TransactionManager.InProgress(stage, layerB))

TransactionManager.CloseAll()


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static bool CloseStageLayer(const UsdStageWeakPtr& stage, const SdfLayerHandle&
return This::Close(stage, layer);
}

static void CloseAllStage() { This::CloseAll(); }

void wrapTransactionManager()
{
{
Expand All @@ -56,6 +58,9 @@ void wrapTransactionManager()
.staticmethod("Open")

.def("Close", CloseStageLayer, (arg("stage"), arg("layer")))
.staticmethod("Close");
.staticmethod("Close")

.def("CloseAll", CloseAllStage)
.staticmethod("CloseAll");
}
}