فهرست منبع

Tweaks the MaterialAsset loading logic to continue to see if the matDefinition already points to an existing object(to avoid needlessly re-executing files over and over), but also validate other cases, and ensures that if we DO have an existing definition, we still process and load it in the asset itself properly.

Areloch 4 سال پیش
والد
کامیت
506621352c
2فایلهای تغییر یافته به همراه18 افزوده شده و 2 حذف شده
  1. 17 2
      Engine/source/T3D/assets/MaterialAsset.cpp
  2. 1 0
      Engine/source/T3D/assets/MaterialAsset.h

+ 17 - 2
Engine/source/T3D/assets/MaterialAsset.cpp

@@ -167,6 +167,12 @@ void MaterialAsset::initializeAsset()
 
    mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
 
+   if (mMatDefinitionName == StringTable->EmptyString())
+   {
+      mLoadedState = Failed;
+      return;
+   }
+
    if (Torque::FS::IsScriptFile(mScriptPath))
    {
       if (!Sim::findObject(mMatDefinitionName))
@@ -180,6 +186,10 @@ void MaterialAsset::initializeAsset()
               mLoadedState = Failed;
           }
       }
+      else
+      {
+         mLoadedState = DefinitionAlreadyExists;
+      }
    }
 
    loadMaterial();
@@ -189,6 +199,12 @@ void MaterialAsset::onAssetRefresh()
 {
    mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
 
+   if (mMatDefinitionName == StringTable->EmptyString())
+   {
+      mLoadedState = Failed;
+      return;
+   }
+
    if (Torque::FS::IsScriptFile(mScriptPath))
    {
       //Since we're refreshing, we can assume that the file we're executing WILL have an existing definition.
@@ -204,7 +220,6 @@ void MaterialAsset::onAssetRefresh()
 
       //And now that we've executed, switch back to the prior behavior
       Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str());
-      
    }
 
    loadMaterial();
@@ -232,7 +247,7 @@ void MaterialAsset::loadMaterial()
    if (mMaterialDefinition)
       SAFE_DELETE(mMaterialDefinition);
 
-   if (mLoadedState == ScriptLoaded && mMatDefinitionName != StringTable->EmptyString())
+   if ((mLoadedState == ScriptLoaded || mLoadedState == DefinitionAlreadyExists) && mMatDefinitionName != StringTable->EmptyString())
    {
       Material* matDef;
       if (!Sim::findObject(mMatDefinitionName, matDef))

+ 1 - 0
Engine/source/T3D/assets/MaterialAsset.h

@@ -73,6 +73,7 @@ public:
    enum MaterialAssetErrCode
    {
       ScriptLoaded = AssetErrCode::Extended,
+      DefinitionAlreadyExists,
       Extended
    };