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

Fixes an issue on layer editor save dialog, where an invalid extension could cause a crash. The fallback is .usd. #2845

Merged
merged 3 commits into from
Jan 26, 2023
Merged
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
19 changes: 17 additions & 2 deletions lib/mayaUsd/utils/utilSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "utilSerialization.h"

#include <mayaUsd/base/tokens.h>
#include <mayaUsd/fileio/jobs/jobArgs.h>
#include <mayaUsd/utils/stageCache.h>
#include <mayaUsd/utils/util.h>
#include <mayaUsd/utils/utilFileSystem.h>
Expand Down Expand Up @@ -105,6 +106,10 @@ bool saveRootLayer(SdfLayerRefPtr layer, const std::string& proxy)
void updateAllCachedStageWithLayer(SdfLayerRefPtr originalLayer, const std::string& newFilePath)
{
SdfLayerRefPtr newLayer = SdfLayer::FindOrOpen(newFilePath);
if (!newLayer) {
TF_WARN("The filename %s is an invalid file name for a layer.", newFilePath.c_str());
return;
}
for (UsdStageCache& cache : UsdMayaStageCache::GetAllCaches()) {
UsdStageCacheContext ctx(cache);
std::vector<UsdStageRefPtr> stages = cache.FindAllMatching(originalLayer);
Expand Down Expand Up @@ -279,9 +284,19 @@ SdfLayerRefPtr saveAnonymousLayer(
return nullptr;
}

saveLayerWithFormat(anonLayer, path, formatArg);
std::string filePath(path);
const std::string& extension = SdfFileFormat::GetFileExtension(filePath);
const std::string defaultExt(UsdMayaTranslatorTokens->UsdFileExtensionDefault.GetText());
const std::string usdCrateExt(UsdMayaTranslatorTokens->UsdFileExtensionCrate.GetText());
const std::string usdASCIIExt(UsdMayaTranslatorTokens->UsdFileExtensionASCII.GetText());
if (extension != defaultExt && extension != usdCrateExt && extension != usdASCIIExt) {
filePath.append(".");
filePath.append(defaultExt.c_str());
}

saveLayerWithFormat(anonLayer, filePath, formatArg);

SdfLayerRefPtr newLayer = SdfLayer::FindOrOpen(path);
SdfLayerRefPtr newLayer = SdfLayer::FindOrOpen(filePath);
if (newLayer) {
if (parent._layerParent) {
parent._layerParent->GetSubLayerPaths().Replace(
Expand Down