Skip to content

Commit

Permalink
Merge pull request #2830 from Autodesk/bailp/MAYA-104552/flush-on-exit
Browse files Browse the repository at this point in the history
MAYA-104552 flush the diagnostic when Maya exits.
  • Loading branch information
seando-adsk authored Feb 16, 2023
2 parents ed1fb6f + 3ece248 commit b383417
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/mayaUsd/utils/diagnosticDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <limits>
#include <memory>
#include <thread>

Expand Down Expand Up @@ -93,6 +94,7 @@ std::unique_ptr<UsdUtilsCoalescingDiagnosticDelegate> _batchedWarnings;
std::unique_ptr<UsdUtilsCoalescingDiagnosticDelegate> _batchedErrors;
std::unique_ptr<TfDiagnosticMgr::Delegate> _waker;
std::unique_ptr<DiagnosticFlusher> _flusher;
MCallbackId _exitCallback;

// The delegate can be installed by multiple plugins (e.g. pxrUsd and
// mayaUsdPlugin), so keep track of installations to ensure that we only add
Expand Down Expand Up @@ -155,7 +157,12 @@ class ErrorOnlyDelegate : public UsdUtilsCoalescingDiagnosticDelegate
class DiagnosticFlusher
{
public:
DiagnosticFlusher() { }
DiagnosticFlusher()
{
if (!IsDiagnosticBatchingEnabled()) {
_maximumUnbatchedDiagnostics = std::numeric_limits<int>::max();
}
}

~DiagnosticFlusher() { }

Expand Down Expand Up @@ -378,6 +385,12 @@ class WakeUpDelegate : public TfDiagnosticMgr::Delegate
void IssueFatalError(const TfCallContext&, const std::string&) override { }
};

void beforeExitCallback(void* /*clientData*/)
{
// Make sure the diagnostic messages are flushed when Maya exits.
UsdMayaDiagnosticDelegate::Flush();
}

} // anonymous namespace

void UsdMayaDiagnosticDelegate::InstallDelegate()
Expand Down Expand Up @@ -405,6 +418,8 @@ void UsdMayaDiagnosticDelegate::InstallDelegate()
// Note: waker accesses the flusher, so the waker must be created
// after the flusher.
_waker = std::make_unique<WakeUpDelegate>();

_exitCallback = MSceneMessage::addCallback(MSceneMessage::kMayaExiting, beforeExitCallback);
}

void UsdMayaDiagnosticDelegate::RemoveDelegate()
Expand All @@ -423,6 +438,8 @@ void UsdMayaDiagnosticDelegate::RemoveDelegate()

Flush();

MMessage::removeCallback(_exitCallback);

// Note: waker accesses the flusher, so the waker must be destroyed
// before the flusher.
_waker.reset();
Expand Down

0 comments on commit b383417

Please sign in to comment.