From b49f19c386525aa5bf6d3ffba65c7fb1d32c7b77 Mon Sep 17 00:00:00 2001 From: Aruki Date: Mon, 4 Feb 2019 23:15:20 -0700 Subject: [PATCH] Fixed crash when creating new projects --- src/.qmake.conf | 2 +- src/Core/GameProject/CGameExporter.cpp | 4 ++- src/Core/GameProject/CResourceEntry.cpp | 18 ++++++++----- src/Core/GameProject/CResourceEntry.h | 2 +- src/Core/GameProject/CResourceStore.cpp | 4 +-- src/Core/GameProject/CResourceStore.h | 2 +- src/Core/Resource/Factory/CResourceFactory.h | 4 +-- templates/MP2/Game.xml | 24 ++++++++--------- templates/MP2/Script/EmperorIngStage1.xml | 2 +- .../MP2/Script/EmperorIngStage2Tentacle.xml | 2 +- ...nStruct25.xml => EmperorIngStage1Data.xml} | 6 ++--- ...9.xml => EmperorIngStage1TentacleData.xml} | 2 +- ...8.xml => EmperorIngStage2TentacleData.xml} | 2 +- templates/PropertyMap.xml | 26 ++++++++++++------- 14 files changed, 57 insertions(+), 43 deletions(-) rename templates/MP2/Structs/{UnknownStruct25.xml => EmperorIngStage1Data.xml} (91%) rename templates/MP2/Structs/{UnknownStruct19.xml => EmperorIngStage1TentacleData.xml} (94%) rename templates/MP2/Structs/{UnknownStruct18.xml => EmperorIngStage2TentacleData.xml} (90%) diff --git a/src/.qmake.conf b/src/.qmake.conf index 090ec4e4..f7171e95 100644 --- a/src/.qmake.conf +++ b/src/.qmake.conf @@ -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' \ diff --git a/src/Core/GameProject/CGameExporter.cpp b/src/Core/GameProject/CGameExporter.cpp index f62f393b..4c55f1e5 100644 --- a/src/Core/GameProject/CGameExporter.cpp +++ b/src/Core/GameProject/CGameExporter.cpp @@ -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); diff --git a/src/Core/GameProject/CResourceEntry.cpp b/src/Core/GameProject/CResourceEntry.cpp index e2229c15..dc31eb59 100644 --- a/src/Core/GameProject/CResourceEntry.cpp +++ b/src/Core/GameProject/CResourceEntry.cpp @@ -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) { diff --git a/src/Core/GameProject/CResourceEntry.h b/src/Core/GameProject/CResourceEntry.h index 21e76a48..fce01af8 100644 --- a/src/Core/GameProject/CResourceEntry.h +++ b/src/Core/GameProject/CResourceEntry.h @@ -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); diff --git a/src/Core/GameProject/CResourceStore.cpp b/src/Core/GameProject/CResourceStore.cpp index 59abf94d..218f3855 100644 --- a/src/Core/GameProject/CResourceStore.cpp +++ b/src/Core/GameProject/CResourceStore.cpp @@ -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; diff --git a/src/Core/GameProject/CResourceStore.h b/src/Core/GameProject/CResourceStore.h index 85cf3a7d..e2ab9c67 100644 --- a/src/Core/GameProject/CResourceStore.h +++ b/src/Core/GameProject/CResourceStore.h @@ -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; diff --git a/src/Core/Resource/Factory/CResourceFactory.h b/src/Core/Resource/Factory/CResourceFactory.h index bbd6a680..5d6b9c2b 100644 --- a/src/Core/Resource/Factory/CResourceFactory.h +++ b/src/Core/Resource/Factory/CResourceFactory.h @@ -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? } } diff --git a/templates/MP2/Game.xml b/templates/MP2/Game.xml index 20331874..f4b3059b 100644 --- a/templates/MP2/Game.xml +++ b/templates/MP2/Game.xml @@ -839,6 +839,18 @@ EditorProperties + + EmperorIngStage1Data + + + + EmperorIngStage1TentacleData + + + + EmperorIngStage2TentacleData + + EmperorIngStage3Data @@ -1307,14 +1319,6 @@ UnknownStruct17 - - UnknownStruct18 - - - - UnknownStruct19 - - UnknownStruct2 @@ -1339,10 +1343,6 @@ UnknownStruct24 - - UnknownStruct25 - - UnknownStruct26 diff --git a/templates/MP2/Script/EmperorIngStage1.xml b/templates/MP2/Script/EmperorIngStage1.xml index 96493d66..35223244 100644 --- a/templates/MP2/Script/EmperorIngStage1.xml +++ b/templates/MP2/Script/EmperorIngStage1.xml @@ -15,7 +15,7 @@ - + diff --git a/templates/MP2/Script/EmperorIngStage2Tentacle.xml b/templates/MP2/Script/EmperorIngStage2Tentacle.xml index 7e0d73d6..fb7ea095 100644 --- a/templates/MP2/Script/EmperorIngStage2Tentacle.xml +++ b/templates/MP2/Script/EmperorIngStage2Tentacle.xml @@ -15,7 +15,7 @@ - + diff --git a/templates/MP2/Structs/UnknownStruct25.xml b/templates/MP2/Structs/EmperorIngStage1Data.xml similarity index 91% rename from templates/MP2/Structs/UnknownStruct25.xml rename to templates/MP2/Structs/EmperorIngStage1Data.xml index 042bc73a..5eb24d9b 100644 --- a/templates/MP2/Structs/UnknownStruct25.xml +++ b/templates/MP2/Structs/EmperorIngStage1Data.xml @@ -1,9 +1,9 @@ - UnknownStruct25 + EmperorIngStage1Data - + @@ -31,7 +31,7 @@ 0.0 - + -1 diff --git a/templates/MP2/Structs/UnknownStruct19.xml b/templates/MP2/Structs/EmperorIngStage1TentacleData.xml similarity index 94% rename from templates/MP2/Structs/UnknownStruct19.xml rename to templates/MP2/Structs/EmperorIngStage1TentacleData.xml index ba2cdc6e..582f185a 100644 --- a/templates/MP2/Structs/UnknownStruct19.xml +++ b/templates/MP2/Structs/EmperorIngStage1TentacleData.xml @@ -1,7 +1,7 @@ - UnknownStruct19 + EmperorIngStage1TentacleData diff --git a/templates/MP2/Structs/UnknownStruct18.xml b/templates/MP2/Structs/EmperorIngStage2TentacleData.xml similarity index 90% rename from templates/MP2/Structs/UnknownStruct18.xml rename to templates/MP2/Structs/EmperorIngStage2TentacleData.xml index 43d4995f..168cf1a8 100644 --- a/templates/MP2/Structs/UnknownStruct18.xml +++ b/templates/MP2/Structs/EmperorIngStage2TentacleData.xml @@ -1,7 +1,7 @@ - UnknownStruct18 + EmperorIngStage2TentacleData 0.0 diff --git a/templates/PropertyMap.xml b/templates/PropertyMap.xml index 33a8f978..42294c19 100644 --- a/templates/PropertyMap.xml +++ b/templates/PropertyMap.xml @@ -1213,10 +1213,6 @@ - - - - @@ -13561,9 +13557,13 @@ + + + + - + @@ -14909,9 +14909,13 @@ + + + + - + @@ -26838,7 +26842,7 @@ - + @@ -29043,7 +29047,7 @@ - + @@ -32857,9 +32861,13 @@ + + + + - +