diff options
author | Antti Määttä <antti.maatta@qt.io> | 2020-10-21 14:56:46 +0300 |
---|---|---|
committer | Antti Määttä <antti.maatta@qt.io> | 2020-10-22 07:34:31 +0300 |
commit | 7c0b903827600c0ecfa55b11e8f889f850eacdc9 (patch) | |
tree | f8129af61964e4ece465803cfe49bc64bb1d8880 /src/Authoring | |
parent | d98e2e6d293031c70484eddf7f4e65e4c2455708 (diff) |
Fix crash when effect is deleted outside project
Fix crash when saving a project which has effect that was deleted outside
the project.
Task-number: QT3DS-4194
Change-Id: I787c713b8a32b217b96abc1e8a987d3a4cf33ade
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Authoring')
4 files changed, 41 insertions, 15 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.cpp b/src/Authoring/Client/Code/Core/Doc/Doc.cpp index 453c2a91..e0d2479b 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.cpp +++ b/src/Authoring/Client/Code/Core/Doc/Doc.cpp @@ -2571,7 +2571,7 @@ void CDoc::SavePresentationFile(CBufferedOutputStream *inOutputStream) } std::shared_ptr<IComposerSerializer> theSerializer(CreateSerializer()); - theSerializer->SerializeScene(theWriter); + theSerializer->SerializeScene(theWriter, GetDocumentDirectory()); SBufferedOutputStreamOutStream theStream(*inOutputStream); CDOMSerializer::WriteXMLHeader(theStream); diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index 02d7a3a1..f2627e05 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -4687,15 +4687,24 @@ public: IDocumentEditor::fixDefaultTexturePaths(theParentInstance); DisplayLoadWarnings(shaderFile, theWarnings, QString()); } else { - if (theHandler) + if (theHandler) { theHandler->DisplayImportFailed(theShaderFile.toQString(), QObject::tr("Unable to load Shader File"), false); + } return 0; } } const SMetaDataDynamicObject *dynObj; dynObj = m_MetaData.GetDynamicObjectByInstance(theParentInstance); + if (!dynObj) { + if (theHandler) { + theHandler->DisplayImportFailed(theShaderFile.toQString(), + QObject::tr("Unable to load Shader File"), + false); + } + return 0; + } TInstanceHandle retval(IDocumentEditor::CreateSceneGraphInstance( theParentInstance, inParent, inSlide, m_DataCore, m_SlideSystem, diff --git a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp index 820c8faf..d3355260 100644 --- a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp +++ b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp @@ -1843,6 +1843,8 @@ struct SComposerSerializerImpl : public IComposerSerializer TInstanceHandleList parents; m_DataCore.GetInstanceParents(inInstance, parents); SMetaDataDynamicObject *dynObj = m_MetaData.GetDynamicObjectByInstance(parents[0]); + if (!dynObj) + return false; for (int i = 0; i < dynObj->m_Properties.size(); i++) { auto &prop = dynObj->m_Properties[i]; for (auto iter = theValues.begin(); iter != theValues.end(); iter++) { @@ -2587,7 +2589,8 @@ struct SComposerSerializerImpl : public IComposerSerializer } void DoSerializeScene(IDOMWriter &inWriter, const Qt3DSDMInstanceHandle *inTopInstances, - QT3DSU32 inCount, bool inWriteParentRefs = false) + QT3DSU32 inCount, bool inWriteParentRefs = false, + const Q3DStudio::CFilePath *inDocumentDirectory = nullptr) { GetAllInstanceGuids(); { @@ -2613,15 +2616,27 @@ struct SComposerSerializerImpl : public IComposerSerializer QT3DS_ASSERT(false); continue; } - IDOMWriter::Scope instScope(inWriter, theType->wide_str()); - inWriter.Att(L"id", GetInstanceId(theMaster)); - // Write out all the properties that are on the instance but are not on *this* - // instance in the meta data. - TPropertyHandleValuePairList theProperties; - GetSpecificInstancePropertyValues(theMaster, theProperties); - erase_if(theProperties, - SMetaDataPropertyEraser(theMaster, m_ObjectDefinitions)); - SerializePropertyList(inWriter, theProperties); + SValue value; + m_DataCore.GetInstancePropertyValue(theMaster, + m_ObjectDefinitions.m_Asset.m_SourcePath, + value); + if (!value.empty()) { + CFilePath sourcePath(value.getData<qt3dsdm::TDataStrPtr>()->GetData()); + CFilePath theFullPath = CFilePath::CombineBaseAndRelative( + (inDocumentDirectory ? (*inDocumentDirectory) : CFilePath()), + sourcePath); + if (!inDocumentDirectory || theFullPath.Exists()) { + IDOMWriter::Scope instScope(inWriter, theType->wide_str()); + inWriter.Att(L"id", GetInstanceId(theMaster)); + // Write out all the properties that are on the instance but are not on *this* + // instance in the meta data. + TPropertyHandleValuePairList theProperties; + GetSpecificInstancePropertyValues(theMaster, theProperties); + erase_if(theProperties, + SMetaDataPropertyEraser(theMaster, m_ObjectDefinitions)); + SerializePropertyList(inWriter, theProperties); + } + } } } inWriter.MoveBefore(L"Classes", L"Graph"); @@ -2878,7 +2893,8 @@ struct SComposerSerializerImpl : public IComposerSerializer } }; - void SerializeScene(IDOMWriter &inWriter) override + void SerializeScene(IDOMWriter &inWriter, + const Q3DStudio::CFilePath &inDocumentDirectory) override { reset(); ScopedPreserveFileIds __preserveFileIds(m_PreserveFileIds); @@ -2892,7 +2908,7 @@ struct SComposerSerializerImpl : public IComposerSerializer if (theGraphRoots.empty()) return; QT3DS_ASSERT(theGraphRoots.size() == 1); - DoSerializeScene(inWriter, &theGraphRoots[0], 1); + DoSerializeScene(inWriter, &theGraphRoots[0], 1, false, &inDocumentDirectory); TGuideHandleList theGuides = m_GuideSystem.GetAllGuides(); // sort the guides by handle value to keep the file as stable as possible. std::sort(theGuides.begin(), theGuides.end()); diff --git a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.h b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.h index 8f8fbb1d..b7e5ed96 100644 --- a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.h +++ b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.h @@ -65,7 +65,8 @@ protected: virtual ~IComposerSerializer() {} public: // Empty graph roots means use the actual graph roots in the asset graph - virtual void SerializeScene(qt3dsdm::IDOMWriter &inWriter) = 0; + virtual void SerializeScene(qt3dsdm::IDOMWriter &inWriter, + const Q3DStudio::CFilePath &inDocumentDirectory) = 0; // Write properties into the active slide until we get to a slide owner, then create new slides. // inActiveSlide may be zero if the top item we find happens to be a scene or a component. // The graph roots hold the top items |