Skip to content

Commit

Permalink
Merge pull request #1601 from Autodesk/t_bailp/MAYA-111932/no-usd-pro…
Browse files Browse the repository at this point in the history
…mpt-during-crash

MAYA-111932 no USD prompt during crash
  • Loading branch information
Krystian Ligenza committed Jul 28, 2021
2 parents 1b229bc + f3f57d2 commit b7ae646
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ if (MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MFrameContext.h")
endif()
endif()

set(MAYA_HAS_CRASH_DETECTION FALSE CACHE INTERNAL "isInCrashHandler")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MGlobal.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MGlobal.h MAYA_HAS_API REGEX "isInCrashHandler")
if(MAYA_HAS_API)
set(MAYA_HAS_CRASH_DETECTION TRUE CACHE INTERNAL "isInCrashHandler")
message(STATUS "Maya has isInCrashHandler API")
endif()
endif()

# handle the QUIETLY and REQUIRED arguments and set MAYA_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
Expand Down
8 changes: 8 additions & 0 deletions lib/mayaUsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ if (MAYA_NEW_POINT_SNAPPING_SUPPORT)
)
endif()

message(STATUS "MAYA_HAS_CRASH_DETECTION is ${MAYA_HAS_CRASH_DETECTION}")
if (MAYA_HAS_CRASH_DETECTION)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
MAYA_HAS_CRASH_DETECTION=1
)
endif()

if (MAYA_LIGHTAPI_VERSION EQUAL 2)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
Expand Down
19 changes: 17 additions & 2 deletions lib/mayaUsd/nodes/layerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ void convertAnonymousLayersRecursive(
}
}

bool isCrashing()
{
#ifdef MAYA_HAS_CRASH_DETECTION
return MGlobal::isInCrashHandler();
#else
return false;
#endif
}

constexpr auto kSaveOptionUICmd = "usdFileSaveOptions(true);";

} // namespace
Expand Down Expand Up @@ -360,7 +369,7 @@ void LayerDatabase::prepareForWriteCheck(bool* retCode, bool isExport)

int dialogResult = true;

if (MGlobal::kInteractive == MGlobal::mayaState()
if (MGlobal::kInteractive == MGlobal::mayaState() && !isCrashing()
&& LayerDatabase::instance().saveInteractionRequired()) {
MGlobal::executeCommand(kSaveOptionUICmd, dialogResult);
}
Expand Down Expand Up @@ -448,7 +457,13 @@ bool LayerDatabase::saveUsd(bool isExport)
auto opt = MayaUsd::utils::serializeUsdEditsLocationOption();

if (MayaUsd::utils::kIgnoreUSDEdits != opt) {
if (_batchSaveDelegate && _proxiesToSave.length() > 0) {
// When Maya is crashing, we don't want to save the the USD file to avoid
// overwriting them with possibly unwanted data. Instead, we will save the
// USD data inside the temporary crash recovery Maya file.
if (isCrashing()) {
result = kPartiallyCompleted;
opt = MayaUsd::utils::kSaveToMayaSceneFile;
} else if (_batchSaveDelegate && _proxiesToSave.length() > 0) {
result = _batchSaveDelegate(_proxiesToSave);
}

Expand Down

0 comments on commit b7ae646

Please sign in to comment.