Cleanup HAPI when Maya is exiting
This is needed when using out-of-process in Maya 2018 on Windows.
Normally, HARS would exit after Maya exits. However, in Maya 2018 on
Windows, Maya tries to wait for HARS to exit, which leads to a deadlock.
#include <maya/MAnimControl.h>
#include <maya/MCallbackIdArray.h>
#include <maya/MEventMessage.h>
+#include <maya/MSceneMessage.h>
#include <maya/MGlobal.h>
#include <maya/MFnPlugin.h>
@@ -446,6 +447,13 @@ cleanupSession()
return true;
}
+void
+mayaExiting(void* clientData)
+{
+ cleanupHAPI();
+ cleanupSession();
+}
+
void updateTimelineCallback(void* clientData)
{
HAPI_TimelineOptions timelineOptions;
@@ -477,6 +485,21 @@ initializeMessageCallbacks()
MCallbackId callbackId;
+ callbackId = MSceneMessage::addCallback(
+ MSceneMessage::kMayaExiting,
+ mayaExiting,
+ NULL,
+ &status
+ );
+ if(status)
+ {
+ messageCallbacks.append(callbackId);
+ }
+ else
+ {
+ CHECK_MSTATUS(status);
+ }
+
callbackId = MEventMessage::addEventCallback(
"playbackRangeSliderChanged",
updateTimelineCallback,
