mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-16 08:27:01 +00:00
CResource: Make BuildDependencyTree() return a unique_ptr
Makes the functions more memory safe in terms of freeing memory in exceptional paths .
This commit is contained in:
@@ -92,7 +92,6 @@ CResourceEntry* CResourceEntry::BuildFromDirectory(CResourceStore *pStore, CResT
|
||||
CResourceEntry::~CResourceEntry()
|
||||
{
|
||||
if (mpResource) delete mpResource;
|
||||
if (mpDependencies) delete mpDependencies;
|
||||
}
|
||||
|
||||
bool CResourceEntry::LoadMetadata()
|
||||
@@ -171,15 +170,11 @@ void CResourceEntry::SerializeEntryInfo(IArchive& rArc, bool MetadataOnly)
|
||||
|
||||
void CResourceEntry::UpdateDependencies()
|
||||
{
|
||||
if (mpDependencies)
|
||||
{
|
||||
delete mpDependencies;
|
||||
mpDependencies = nullptr;
|
||||
}
|
||||
mpDependencies.reset();
|
||||
|
||||
if (!mpTypeInfo->CanHaveDependencies())
|
||||
{
|
||||
mpDependencies = new CDependencyTree();
|
||||
mpDependencies = std::make_unique<CDependencyTree>();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -191,7 +186,7 @@ void CResourceEntry::UpdateDependencies()
|
||||
if (!mpResource)
|
||||
{
|
||||
errorf("Unable to update cached dependencies; failed to load resource");
|
||||
mpDependencies = new CDependencyTree();
|
||||
mpDependencies = std::make_unique<CDependencyTree>();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class CResourceEntry
|
||||
CResource *mpResource;
|
||||
CResTypeInfo *mpTypeInfo;
|
||||
CResourceStore *mpStore;
|
||||
CDependencyTree *mpDependencies;
|
||||
std::unique_ptr<CDependencyTree> mpDependencies;
|
||||
CAssetID mID;
|
||||
CVirtualDirectory *mpDirectory;
|
||||
TString mName;
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
CResource* Resource() const { return mpResource; }
|
||||
CResTypeInfo* TypeInfo() const { return mpTypeInfo; }
|
||||
CResourceStore* ResourceStore() const { return mpStore; }
|
||||
CDependencyTree* Dependencies() const { return mpDependencies; }
|
||||
CDependencyTree* Dependencies() const { return mpDependencies.get(); }
|
||||
CAssetID ID() const { return mID; }
|
||||
CVirtualDirectory* Directory() const { return mpDirectory; }
|
||||
TString DirectoryPath() const { return mpDirectory->FullPath(); }
|
||||
|
||||
Reference in New Issue
Block a user