Fixed crash when creating new projects

This commit is contained in:
Aruki
2019-02-04 23:15:20 -07:00
parent 1baa48de34
commit b49f19c386
14 changed files with 57 additions and 43 deletions

View File

@@ -16,7 +16,7 @@ EXTERNALS_DIR = $$PWD/../externals
PWE_MAIN_INCLUDE = $$PWD
DEFINES += 'APP_NAME=\"\\\"Prime World Editor\\\"\"' \
'APP_VERSION=\"\\\"1.2.1\\\"\"'
'APP_VERSION=\"\\\"1.2.2\\\"\"'
PUBLIC_RELEASE {
DEFINES += 'PUBLIC_RELEASE=1' \

View File

@@ -626,7 +626,9 @@ void CGameExporter::ExportResource(SResourceInstance& rRes)
Name = rRes.ResourceID.ToString();
#endif
CResourceEntry *pEntry = mpStore->CreateNewResource(rRes.ResourceID, CResTypeInfo::TypeForCookedExtension(mGame, rRes.ResourceType)->Type(), Directory, Name);
CResourceEntry *pEntry = mpStore->CreateNewResource(rRes.ResourceID,
CResTypeInfo::TypeForCookedExtension(mGame, rRes.ResourceType)->Type(),
Directory, Name, true);
// Set flags
pEntry->SetFlag(EResEntryFlag::IsBaseGameResource);

View File

@@ -24,7 +24,7 @@ CResourceEntry::CResourceEntry(CResourceStore *pStore)
// Static constructors
CResourceEntry* CResourceEntry::CreateNewResource(CResourceStore *pStore, const CAssetID& rkID,
const TString& rkDir, const TString& rkName,
EResourceType Type)
EResourceType Type, bool ExistingResource /*= false*/)
{
// Initialize all entry info with the input data.
CResourceEntry *pEntry = new CResourceEntry(pStore);
@@ -41,12 +41,16 @@ CResourceEntry* CResourceEntry::CreateNewResource(CResourceStore *pStore, const
pEntry->mMetadataDirty = true;
// Check if the data exists or not. If so, then we are creating an entry for an existing resource (game exporter).
// If not, we want to initiate the new resource data and save it as soon as possible.
if (!pEntry->HasCookedVersion())
// If this is a new resource (i.e. not a base game resource that we are currently exporting),
// then instantiate the new resource data so it can be saved as soon as possible.
if (!ExistingResource)
{
pEntry->mpResource = CResourceFactory::SpawnResource(pEntry);
pEntry->mpResource->InitializeNewResource();
pEntry->mpResource = CResourceFactory::CreateResource(pEntry);
if (pEntry->mpResource)
{
pEntry->mpResource->InitializeNewResource();
}
}
return pEntry;
@@ -394,7 +398,7 @@ CResource* CResourceEntry::Load()
// support serialization yet) then load the cooked version as a backup.
if (HasRawVersion())
{
mpResource = CResourceFactory::SpawnResource(this);
mpResource = CResourceFactory::CreateResource(this);
if (mpResource)
{

View File

@@ -46,7 +46,7 @@ class CResourceEntry
public:
static CResourceEntry* CreateNewResource(CResourceStore *pStore, const CAssetID& rkID,
const TString& rkDir, const TString& rkName,
EResourceType Type);
EResourceType Type, bool ExistingResource = false);
static CResourceEntry* BuildFromArchive(CResourceStore *pStore, IArchive& rArc);
static CResourceEntry* BuildFromDirectory(CResourceStore *pStore, CResTypeInfo *pTypeInfo,
const TString& rkDirPath, const TString& rkName);

View File

@@ -445,7 +445,7 @@ bool CResourceStore::IsResourceRegistered(const CAssetID& rkID) const
return FindEntry(rkID) != nullptr;
}
CResourceEntry* CResourceStore::CreateNewResource(const CAssetID& rkID, EResourceType Type, const TString& rkDir, const TString& rkName)
CResourceEntry* CResourceStore::CreateNewResource(const CAssetID& rkID, EResourceType Type, const TString& rkDir, const TString& rkName, bool ExistingResource /*= false*/)
{
CResourceEntry *pEntry = FindEntry(rkID);
@@ -457,7 +457,7 @@ CResourceEntry* CResourceStore::CreateNewResource(const CAssetID& rkID, EResourc
// Validate directory
if (IsValidResourcePath(rkDir, rkName))
{
pEntry = CResourceEntry::CreateNewResource(this, rkID, rkDir, rkName, Type);
pEntry = CResourceEntry::CreateNewResource(this, rkID, rkDir, rkName, Type, ExistingResource);
mResourceEntries[rkID] = pEntry;
mDatabaseCacheDirty = true;

View File

@@ -55,7 +55,7 @@ public:
TString DeletedResourcePath() const;
bool IsResourceRegistered(const CAssetID& rkID) const;
CResourceEntry* CreateNewResource(const CAssetID& rkID, EResourceType Type, const TString& rkDir, const TString& rkName);
CResourceEntry* CreateNewResource(const CAssetID& rkID, EResourceType Type, const TString& rkDir, const TString& rkName, bool ExistingResource = false);
CResourceEntry* FindEntry(const CAssetID& rkID) const;
CResourceEntry* FindEntry(const TString& rkPath) const;
bool AreAllEntriesValid() const;

View File

@@ -32,7 +32,7 @@ class CResourceFactory
CResourceFactory() {}
public:
static CResource* SpawnResource(CResourceEntry *pEntry)
static CResource* CreateResource(CResourceEntry *pEntry)
{
switch (pEntry->ResourceType())
{
@@ -58,7 +58,7 @@ public:
case EResourceType::StringTable: return new CStringTable(pEntry);
case EResourceType::Texture: return new CTexture(pEntry);
case EResourceType::World: return new CWorld(pEntry);
default: return nullptr; // should it return a CResource instead?
default: return nullptr; // should it return a CResource instead?
}
}